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: getinfo.c,v 1.1.1.1 2008-09-23 16:32:05 hoffman Exp $
22 ***************************************************************************/
26 #include <curl/curl.h>
37 #include "connect.h" /* Curl_getconnectinfo() */
39 /* Make this the last #include */
43 * This is supposed to be called in the beginning of a perform() session
44 * and should reset all session-info variables
46 CURLcode
Curl_initinfo(struct SessionHandle
*data
)
48 struct Progress
*pro
= &data
->progress
;
49 struct PureInfo
*info
=&data
->info
;
53 pro
->t_pretransfer
= 0;
54 pro
->t_starttransfer
= 0;
60 info
->filetime
=-1; /* -1 is an illegal time and thus means unknown */
63 free(info
->contenttype
);
64 info
->contenttype
= NULL
;
66 info
->header_size
= 0;
67 info
->request_size
= 0;
68 info
->numconnects
= 0;
72 CURLcode
Curl_getinfo(struct SessionHandle
*data
, CURLINFO info
, ...)
75 long *param_longp
=NULL
;
76 double *param_doublep
=NULL
;
77 char **param_charp
=NULL
;
78 struct curl_slist
**param_slistp
=NULL
;
82 return CURLE_BAD_FUNCTION_ARGUMENT
;
86 type
= CURLINFO_TYPEMASK
& (int)info
;
89 param_charp
= va_arg(arg
, char **);
90 if(NULL
== param_charp
)
91 return CURLE_BAD_FUNCTION_ARGUMENT
;
94 param_longp
= va_arg(arg
, long *);
95 if(NULL
== param_longp
)
96 return CURLE_BAD_FUNCTION_ARGUMENT
;
99 param_doublep
= va_arg(arg
, double *);
100 if(NULL
== param_doublep
)
101 return CURLE_BAD_FUNCTION_ARGUMENT
;
104 param_slistp
= va_arg(arg
, struct curl_slist
**);
105 if(NULL
== param_slistp
)
106 return CURLE_BAD_FUNCTION_ARGUMENT
;
109 return CURLE_BAD_FUNCTION_ARGUMENT
;
113 case CURLINFO_EFFECTIVE_URL
:
114 *param_charp
= data
->change
.url
?data
->change
.url
:(char *)"";
116 case CURLINFO_RESPONSE_CODE
:
117 *param_longp
= data
->info
.httpcode
;
119 case CURLINFO_HTTP_CONNECTCODE
:
120 *param_longp
= data
->info
.httpproxycode
;
122 case CURLINFO_FILETIME
:
123 *param_longp
= data
->info
.filetime
;
125 case CURLINFO_HEADER_SIZE
:
126 *param_longp
= data
->info
.header_size
;
128 case CURLINFO_REQUEST_SIZE
:
129 *param_longp
= data
->info
.request_size
;
131 case CURLINFO_TOTAL_TIME
:
132 *param_doublep
= data
->progress
.timespent
;
134 case CURLINFO_NAMELOOKUP_TIME
:
135 *param_doublep
= data
->progress
.t_nslookup
;
137 case CURLINFO_CONNECT_TIME
:
138 *param_doublep
= data
->progress
.t_connect
;
140 case CURLINFO_APPCONNECT_TIME
:
141 *param_doublep
= data
->progress
.t_appconnect
;
143 case CURLINFO_PRETRANSFER_TIME
:
144 *param_doublep
= data
->progress
.t_pretransfer
;
146 case CURLINFO_STARTTRANSFER_TIME
:
147 *param_doublep
= data
->progress
.t_starttransfer
;
149 case CURLINFO_SIZE_UPLOAD
:
150 *param_doublep
= (double)data
->progress
.uploaded
;
152 case CURLINFO_SIZE_DOWNLOAD
:
153 *param_doublep
= (double)data
->progress
.downloaded
;
155 case CURLINFO_SPEED_DOWNLOAD
:
156 *param_doublep
= (double)data
->progress
.dlspeed
;
158 case CURLINFO_SPEED_UPLOAD
:
159 *param_doublep
= (double)data
->progress
.ulspeed
;
161 case CURLINFO_SSL_VERIFYRESULT
:
162 *param_longp
= data
->set
.ssl
.certverifyresult
;
164 case CURLINFO_CONTENT_LENGTH_DOWNLOAD
:
165 *param_doublep
= (double)data
->progress
.size_dl
;
167 case CURLINFO_CONTENT_LENGTH_UPLOAD
:
168 *param_doublep
= (double)data
->progress
.size_ul
;
170 case CURLINFO_REDIRECT_TIME
:
171 *param_doublep
= data
->progress
.t_redirect
;
173 case CURLINFO_REDIRECT_COUNT
:
174 *param_longp
= data
->set
.followlocation
;
176 case CURLINFO_CONTENT_TYPE
:
177 *param_charp
= data
->info
.contenttype
;
179 case CURLINFO_PRIVATE
:
180 *param_charp
= (char *) data
->set
.private_data
;
182 case CURLINFO_HTTPAUTH_AVAIL
:
183 *param_longp
= data
->info
.httpauthavail
;
185 case CURLINFO_PROXYAUTH_AVAIL
:
186 *param_longp
= data
->info
.proxyauthavail
;
188 case CURLINFO_OS_ERRNO
:
189 *param_longp
= data
->state
.os_errno
;
191 case CURLINFO_NUM_CONNECTS
:
192 *param_longp
= data
->info
.numconnects
;
194 case CURLINFO_SSL_ENGINES
:
195 *param_slistp
= Curl_ssl_engines_list(data
);
197 case CURLINFO_COOKIELIST
:
198 *param_slistp
= Curl_cookie_list(data
);
200 case CURLINFO_FTP_ENTRY_PATH
:
201 /* Return the entrypath string from the most recent connection.
202 This pointer was copied from the connectdata structure by FTP.
203 The actual string may be free()ed by subsequent libcurl calls so
204 it must be copied to a safer area before the next libcurl call.
205 Callers must never free it themselves. */
206 *param_charp
= data
->state
.most_recent_ftp_entrypath
;
208 case CURLINFO_LASTSOCKET
:
209 (void)Curl_getconnectinfo(data
, param_longp
, NULL
);
211 case CURLINFO_REDIRECT_URL
:
212 /* Return the URL this request would have been redirected to if that
213 option had been enabled! */
214 *param_charp
= data
->info
.wouldredirect
;
216 case CURLINFO_PRIMARY_IP
:
217 /* Return the ip address of the most recent (primary) connection */
218 *param_charp
= data
->info
.ip
;
221 return CURLE_BAD_FUNCTION_ARGUMENT
;