1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2010, 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.
22 ***************************************************************************/
26 #include <curl/curl.h>
35 #include "curl_memory.h"
37 #include "connect.h" /* Curl_getconnectinfo() */
40 /* Make this the last #include */
44 * This is supposed to be called in the beginning of a perform() session
45 * and should reset all session-info variables
47 CURLcode Curl_initinfo(struct SessionHandle *data)
49 struct Progress *pro = &data->progress;
50 struct PureInfo *info =&data->info;
54 pro->t_pretransfer = 0;
55 pro->t_starttransfer = 0;
61 info->filetime=-1; /* -1 is an illegal time and thus means unknown */
64 free(info->contenttype);
65 info->contenttype = NULL;
67 info->header_size = 0;
68 info->request_size = 0;
69 info->numconnects = 0;
73 CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...)
76 long *param_longp=NULL;
77 double *param_doublep=NULL;
78 char **param_charp=NULL;
79 struct curl_slist **param_slistp=NULL;
83 struct curl_certinfo * to_certinfo;
84 struct curl_slist * to_slist;
88 return CURLE_BAD_FUNCTION_ARGUMENT;
92 type = CURLINFO_TYPEMASK & (int)info;
95 param_charp = va_arg(arg, char **);
96 if(NULL == param_charp)
97 return CURLE_BAD_FUNCTION_ARGUMENT;
100 param_longp = va_arg(arg, long *);
101 if(NULL == param_longp)
102 return CURLE_BAD_FUNCTION_ARGUMENT;
104 case CURLINFO_DOUBLE:
105 param_doublep = va_arg(arg, double *);
106 if(NULL == param_doublep)
107 return CURLE_BAD_FUNCTION_ARGUMENT;
110 param_slistp = va_arg(arg, struct curl_slist **);
111 if(NULL == param_slistp)
112 return CURLE_BAD_FUNCTION_ARGUMENT;
115 return CURLE_BAD_FUNCTION_ARGUMENT;
119 case CURLINFO_EFFECTIVE_URL:
120 *param_charp = data->change.url?data->change.url:(char *)"";
122 case CURLINFO_RESPONSE_CODE:
123 *param_longp = data->info.httpcode;
125 case CURLINFO_HTTP_CONNECTCODE:
126 *param_longp = data->info.httpproxycode;
128 case CURLINFO_FILETIME:
129 *param_longp = data->info.filetime;
131 case CURLINFO_HEADER_SIZE:
132 *param_longp = data->info.header_size;
134 case CURLINFO_REQUEST_SIZE:
135 *param_longp = data->info.request_size;
137 case CURLINFO_TOTAL_TIME:
138 *param_doublep = data->progress.timespent;
140 case CURLINFO_NAMELOOKUP_TIME:
141 *param_doublep = data->progress.t_nslookup;
143 case CURLINFO_CONNECT_TIME:
144 *param_doublep = data->progress.t_connect;
146 case CURLINFO_APPCONNECT_TIME:
147 *param_doublep = data->progress.t_appconnect;
149 case CURLINFO_PRETRANSFER_TIME:
150 *param_doublep = data->progress.t_pretransfer;
152 case CURLINFO_STARTTRANSFER_TIME:
153 *param_doublep = data->progress.t_starttransfer;
155 case CURLINFO_SIZE_UPLOAD:
156 *param_doublep = (double)data->progress.uploaded;
158 case CURLINFO_SIZE_DOWNLOAD:
159 *param_doublep = (double)data->progress.downloaded;
161 case CURLINFO_SPEED_DOWNLOAD:
162 *param_doublep = (double)data->progress.dlspeed;
164 case CURLINFO_SPEED_UPLOAD:
165 *param_doublep = (double)data->progress.ulspeed;
167 case CURLINFO_SSL_VERIFYRESULT:
168 *param_longp = data->set.ssl.certverifyresult;
170 case CURLINFO_CONTENT_LENGTH_DOWNLOAD:
171 *param_doublep = (data->progress.flags & PGRS_DL_SIZE_KNOWN)?
172 (double)data->progress.size_dl:-1;
174 case CURLINFO_CONTENT_LENGTH_UPLOAD:
175 *param_doublep = (data->progress.flags & PGRS_UL_SIZE_KNOWN)?
176 (double)data->progress.size_ul:-1;
178 case CURLINFO_REDIRECT_TIME:
179 *param_doublep = data->progress.t_redirect;
181 case CURLINFO_REDIRECT_COUNT:
182 *param_longp = data->set.followlocation;
184 case CURLINFO_CONTENT_TYPE:
185 *param_charp = data->info.contenttype;
187 case CURLINFO_PRIVATE:
188 *param_charp = (char *) data->set.private_data;
190 case CURLINFO_HTTPAUTH_AVAIL:
191 *param_longp = data->info.httpauthavail;
193 case CURLINFO_PROXYAUTH_AVAIL:
194 *param_longp = data->info.proxyauthavail;
196 case CURLINFO_OS_ERRNO:
197 *param_longp = data->state.os_errno;
199 case CURLINFO_NUM_CONNECTS:
200 *param_longp = data->info.numconnects;
202 case CURLINFO_SSL_ENGINES:
203 *param_slistp = Curl_ssl_engines_list(data);
205 case CURLINFO_COOKIELIST:
206 *param_slistp = Curl_cookie_list(data);
208 case CURLINFO_FTP_ENTRY_PATH:
209 /* Return the entrypath string from the most recent connection.
210 This pointer was copied from the connectdata structure by FTP.
211 The actual string may be free()ed by subsequent libcurl calls so
212 it must be copied to a safer area before the next libcurl call.
213 Callers must never free it themselves. */
214 *param_charp = data->state.most_recent_ftp_entrypath;
216 case CURLINFO_LASTSOCKET:
217 (void)Curl_getconnectinfo(data, param_longp, NULL);
219 case CURLINFO_REDIRECT_URL:
220 /* Return the URL this request would have been redirected to if that
221 option had been enabled! */
222 *param_charp = data->info.wouldredirect;
224 case CURLINFO_PRIMARY_IP:
225 /* Return the ip address of the most recent (primary) connection */
226 *param_charp = data->info.ip;
228 case CURLINFO_CERTINFO:
229 /* Return the a pointer to the certinfo struct. Not really an slist
230 pointer but we can pretend it is here */
231 ptr.to_certinfo = &data->info.certs;
232 *param_slistp = ptr.to_slist;
234 case CURLINFO_CONDITION_UNMET:
235 /* return if the condition prevented the document to get transfered */
236 *param_longp = data->info.timecond;
238 case CURLINFO_RTSP_SESSION_ID:
239 *param_charp = data->set.str[STRING_RTSP_SESSION_ID];
241 case CURLINFO_RTSP_CLIENT_CSEQ:
242 *param_longp = data->state.rtsp_next_client_CSeq;
244 case CURLINFO_RTSP_SERVER_CSEQ:
245 *param_longp = data->state.rtsp_next_server_CSeq;
247 case CURLINFO_RTSP_CSEQ_RECV:
248 *param_longp = data->state.rtsp_CSeq_recv;
252 return CURLE_BAD_FUNCTION_ARGUMENT;