1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2008, 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 * $Id: writeout.c,v 1.1.1.1 2008-09-23 16:32:06 hoffman Exp $
22 ***************************************************************************/
29 #ifdef HAVE_SYS_TYPES_H
30 #include <sys/types.h>
32 #ifdef HAVE_SYS_SELECT_H
33 #include <sys/select.h>
36 #include <curl/curl.h>
38 #define _MPRINTF_REPLACE /* we want curl-functions instead of native ones */
39 #include <curl/mprintf.h>
44 VAR_NONE
, /* must be the first */
50 VAR_STARTTRANSFER_TIME
,
66 VAR_SSL_VERIFY_RESULT
,
67 VAR_NUM_OF_VARS
/* must be the last */
76 static const struct variable replacements
[]={
77 {"url_effective", VAR_EFFECTIVE_URL
},
78 {"http_code", VAR_HTTP_CODE
},
79 {"response_code", VAR_HTTP_CODE
},
80 {"http_connect", VAR_HTTP_CODE_PROXY
},
81 {"time_total", VAR_TOTAL_TIME
},
82 {"time_namelookup", VAR_NAMELOOKUP_TIME
},
83 {"time_connect", VAR_CONNECT_TIME
},
84 {"time_appconnect", VAR_APPCONNECT_TIME
},
85 {"time_pretransfer", VAR_PRETRANSFER_TIME
},
86 {"time_starttransfer", VAR_STARTTRANSFER_TIME
},
87 {"size_header", VAR_HEADER_SIZE
},
88 {"size_request", VAR_REQUEST_SIZE
},
89 {"size_download", VAR_SIZE_DOWNLOAD
},
90 {"size_upload", VAR_SIZE_UPLOAD
},
91 {"speed_download", VAR_SPEED_DOWNLOAD
},
92 {"speed_upload", VAR_SPEED_UPLOAD
},
93 {"content_type", VAR_CONTENT_TYPE
},
94 {"num_connects", VAR_NUM_CONNECTS
},
95 {"time_redirect", VAR_REDIRECT_TIME
},
96 {"num_redirects", VAR_REDIRECT_COUNT
},
97 {"ftp_entry_path", VAR_FTP_ENTRY_PATH
},
98 {"redirect_url", VAR_REDIRECT_URL
},
99 {"ssl_verify_result", VAR_SSL_VERIFY_RESULT
},
103 void ourWriteOut(CURL
*curl
, const char *writeinfo
)
105 FILE *stream
= stdout
;
106 const char *ptr
=writeinfo
;
114 /* an escaped %-letter */
119 /* this is meant as a variable to output */
123 if(('{' == ptr
[1]) && (end
=strchr(ptr
, '}'))) {
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
, &doubleinfo
))
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
, &doubleinfo
))
216 fprintf(stream
, "%.0f", doubleinfo
);
218 case VAR_SPEED_DOWNLOAD
:
220 curl_easy_getinfo(curl
, CURLINFO_SPEED_DOWNLOAD
, &doubleinfo
))
221 fprintf(stream
, "%.3f", doubleinfo
);
223 case VAR_SPEED_UPLOAD
:
225 curl_easy_getinfo(curl
, CURLINFO_SPEED_UPLOAD
, &doubleinfo
))
226 fprintf(stream
, "%.3f", doubleinfo
);
228 case VAR_CONTENT_TYPE
:
230 curl_easy_getinfo(curl
, CURLINFO_CONTENT_TYPE
, &stringp
))
232 fputs(stringp
, stream
);
234 case VAR_FTP_ENTRY_PATH
:
236 curl_easy_getinfo(curl
, CURLINFO_FTP_ENTRY_PATH
, &stringp
))
238 fputs(stringp
, stream
);
240 case VAR_REDIRECT_URL
:
242 curl_easy_getinfo(curl
, CURLINFO_REDIRECT_URL
, &stringp
))
244 fputs(stringp
, stream
);
246 case VAR_SSL_VERIFY_RESULT
:
248 curl_easy_getinfo(curl
, CURLINFO_SSL_VERIFYRESULT
, &longinfo
))
249 fprintf(stream
, "%ld", longinfo
);
258 fprintf(stderr
, "curl: unknown --write-out variable: '%s'\n", ptr
);
260 ptr
=end
+1; /* pass the end */
264 /* illegal syntax, then just output the characters that are used */
266 fputc(ptr
[1], stream
);
271 else if('\\' == *ptr
) {
283 /* unknown, just output this */
285 fputc(ptr
[1], stream
);