1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2006, 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.2 2007/03/15 19:22:13 andy Exp $
22 ***************************************************************************/
26 #include <curl/curl.h>
38 /* Make this the last #include */
42 * This is supposed to be called in the beginning of a perform() session
43 * and should reset all session-info variables
45 CURLcode
Curl_initinfo(struct SessionHandle
*data
)
47 struct Progress
*pro
= &data
->progress
;
48 struct PureInfo
*info
=&data
->info
;
52 pro
->t_pretransfer
= 0;
53 pro
->t_starttransfer
= 0;
59 info
->filetime
=-1; /* -1 is an illegal time and thus means unknown */
61 if (info
->contenttype
)
62 free(info
->contenttype
);
63 info
->contenttype
= NULL
;
65 info
->header_size
= 0;
66 info
->request_size
= 0;
67 info
->numconnects
= 0;
71 CURLcode
Curl_getinfo(struct SessionHandle
*data
, CURLINFO info
, ...)
74 long *param_longp
=NULL
;
75 double *param_doublep
=NULL
;
76 char **param_charp
=NULL
;
77 struct curl_slist
**param_slistp
=NULL
;
81 return CURLE_BAD_FUNCTION_ARGUMENT
;
85 switch(info
&CURLINFO_TYPEMASK
) {
87 return CURLE_BAD_FUNCTION_ARGUMENT
;
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
;
111 case CURLINFO_EFFECTIVE_URL
:
112 *param_charp
= data
->change
.url
?data
->change
.url
:(char *)"";
114 case CURLINFO_RESPONSE_CODE
:
115 *param_longp
= data
->info
.httpcode
;
117 case CURLINFO_HTTP_CONNECTCODE
:
118 *param_longp
= data
->info
.httpproxycode
;
120 case CURLINFO_FILETIME
:
121 *param_longp
= data
->info
.filetime
;
123 case CURLINFO_HEADER_SIZE
:
124 *param_longp
= data
->info
.header_size
;
126 case CURLINFO_REQUEST_SIZE
:
127 *param_longp
= data
->info
.request_size
;
129 case CURLINFO_TOTAL_TIME
:
130 *param_doublep
= data
->progress
.timespent
;
132 case CURLINFO_NAMELOOKUP_TIME
:
133 *param_doublep
= data
->progress
.t_nslookup
;
135 case CURLINFO_CONNECT_TIME
:
136 *param_doublep
= data
->progress
.t_connect
;
138 case CURLINFO_PRETRANSFER_TIME
:
139 *param_doublep
= data
->progress
.t_pretransfer
;
141 case CURLINFO_STARTTRANSFER_TIME
:
142 *param_doublep
= data
->progress
.t_starttransfer
;
144 case CURLINFO_SIZE_UPLOAD
:
145 *param_doublep
= (double)data
->progress
.uploaded
;
147 case CURLINFO_SIZE_DOWNLOAD
:
148 *param_doublep
= (double)data
->progress
.downloaded
;
150 case CURLINFO_SPEED_DOWNLOAD
:
151 *param_doublep
= (double)data
->progress
.dlspeed
;
153 case CURLINFO_SPEED_UPLOAD
:
154 *param_doublep
= (double)data
->progress
.ulspeed
;
156 case CURLINFO_SSL_VERIFYRESULT
:
157 *param_longp
= data
->set
.ssl
.certverifyresult
;
159 case CURLINFO_CONTENT_LENGTH_DOWNLOAD
:
160 *param_doublep
= (double)data
->progress
.size_dl
;
162 case CURLINFO_CONTENT_LENGTH_UPLOAD
:
163 *param_doublep
= (double)data
->progress
.size_ul
;
165 case CURLINFO_REDIRECT_TIME
:
166 *param_doublep
= data
->progress
.t_redirect
;
168 case CURLINFO_REDIRECT_COUNT
:
169 *param_longp
= data
->set
.followlocation
;
171 case CURLINFO_CONTENT_TYPE
:
172 *param_charp
= data
->info
.contenttype
;
174 case CURLINFO_PRIVATE
:
175 *param_charp
= data
->set
.private_data
;
177 case CURLINFO_HTTPAUTH_AVAIL
:
178 *param_longp
= data
->info
.httpauthavail
;
180 case CURLINFO_PROXYAUTH_AVAIL
:
181 *param_longp
= data
->info
.proxyauthavail
;
183 case CURLINFO_OS_ERRNO
:
184 *param_longp
= data
->state
.os_errno
;
186 case CURLINFO_NUM_CONNECTS
:
187 *param_longp
= data
->info
.numconnects
;
189 case CURLINFO_SSL_ENGINES
:
190 *param_slistp
= Curl_ssl_engines_list(data
);
192 case CURLINFO_COOKIELIST
:
193 *param_slistp
= Curl_cookie_list(data
);
195 case CURLINFO_FTP_ENTRY_PATH
:
196 /* Return the entrypath string from the most recent connection.
197 This pointer was copied from the connectdata structure by FTP.
198 The actual string may be free()ed by subsequent libcurl calls so
199 it must be copied to a safer area before the next libcurl call.
200 Callers must never free it themselves. */
201 *param_charp
= data
->state
.most_recent_ftp_entrypath
;
203 case CURLINFO_LASTSOCKET
:
204 if((data
->state
.lastconnect
!= -1) &&
205 (data
->state
.connc
->connects
[data
->state
.lastconnect
] != NULL
)) {
206 struct connectdata
*c
= data
->state
.connc
->connects
207 [data
->state
.lastconnect
];
208 *param_longp
= c
->sock
[FIRSTSOCKET
];
209 /* we have a socket connected, let's determine if the server shut down */
210 /* determine if ssl */
211 if(c
->ssl
[FIRSTSOCKET
].use
) {
212 /* use the SSL context */
213 if (!Curl_ssl_check_cxn(c
))
214 *param_longp
= -1; /* FIN received */
216 /* Minix 3.1 doesn't support any flags on recv; just assume socket is OK */
220 if(recv((RECV_TYPE_ARG1
)c
->sock
[FIRSTSOCKET
], (RECV_TYPE_ARG2
)&buf
,
221 (RECV_TYPE_ARG3
)1, (RECV_TYPE_ARG4
)MSG_PEEK
) == 0) {
222 *param_longp
= -1; /* FIN received */
231 return CURLE_BAD_FUNCTION_ARGUMENT
;