1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2009, 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 ***************************************************************************/
28 #ifdef HAVE_SYS_TYPES_H
29 #include <sys/types.h>
31 #ifdef HAVE_SYS_SELECT_H
32 #include <sys/select.h>
35 #include <curl/curl.h>
37 #define _MPRINTF_REPLACE /* we want curl-functions instead of native ones */
38 #include <curl/mprintf.h>
43 VAR_NONE, /* must be the first */
49 VAR_STARTTRANSFER_TIME,
65 VAR_SSL_VERIFY_RESULT,
66 VAR_NUM_OF_VARS /* must be the last */
75 static const struct variable replacements[]={
76 {"url_effective", VAR_EFFECTIVE_URL},
77 {"http_code", VAR_HTTP_CODE},
78 {"response_code", VAR_HTTP_CODE},
79 {"http_connect", VAR_HTTP_CODE_PROXY},
80 {"time_total", VAR_TOTAL_TIME},
81 {"time_namelookup", VAR_NAMELOOKUP_TIME},
82 {"time_connect", VAR_CONNECT_TIME},
83 {"time_appconnect", VAR_APPCONNECT_TIME},
84 {"time_pretransfer", VAR_PRETRANSFER_TIME},
85 {"time_starttransfer", VAR_STARTTRANSFER_TIME},
86 {"size_header", VAR_HEADER_SIZE},
87 {"size_request", VAR_REQUEST_SIZE},
88 {"size_download", VAR_SIZE_DOWNLOAD},
89 {"size_upload", VAR_SIZE_UPLOAD},
90 {"speed_download", VAR_SPEED_DOWNLOAD},
91 {"speed_upload", VAR_SPEED_UPLOAD},
92 {"content_type", VAR_CONTENT_TYPE},
93 {"num_connects", VAR_NUM_CONNECTS},
94 {"time_redirect", VAR_REDIRECT_TIME},
95 {"num_redirects", VAR_REDIRECT_COUNT},
96 {"ftp_entry_path", VAR_FTP_ENTRY_PATH},
97 {"redirect_url", VAR_REDIRECT_URL},
98 {"ssl_verify_result", VAR_SSL_VERIFY_RESULT},
102 void ourWriteOut(CURL *curl, 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, &doubleinfo))
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, &doubleinfo))
215 fprintf(stream, "%.0f", doubleinfo);
217 case VAR_SPEED_DOWNLOAD:
219 curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD, &doubleinfo))
220 fprintf(stream, "%.3f", doubleinfo);
222 case VAR_SPEED_UPLOAD:
224 curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &doubleinfo))
225 fprintf(stream, "%.3f", doubleinfo);
227 case VAR_CONTENT_TYPE:
229 curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &stringp))
231 fputs(stringp, stream);
233 case VAR_FTP_ENTRY_PATH:
235 curl_easy_getinfo(curl, CURLINFO_FTP_ENTRY_PATH, &stringp))
237 fputs(stringp, stream);
239 case VAR_REDIRECT_URL:
241 curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &stringp))
243 fputs(stringp, stream);
245 case VAR_SSL_VERIFY_RESULT:
247 curl_easy_getinfo(curl, CURLINFO_SSL_VERIFYRESULT, &longinfo))
248 fprintf(stream, "%ld", longinfo);
257 fprintf(stderr, "curl: unknown --write-out variable: '%s'\n", ptr);
259 ptr=end+1; /* pass the end */
263 /* illegal syntax, then just output the characters that are used */
265 fputc(ptr[1], stream);
270 else if('\\' == *ptr) {
282 /* unknown, just output this */
284 fputc(ptr[1], stream);