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.
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;
83 return CURLE_BAD_FUNCTION_ARGUMENT;
87 switch(info&CURLINFO_TYPEMASK) {
89 return CURLE_BAD_FUNCTION_ARGUMENT;
91 param_charp = va_arg(arg, char **);
92 if(NULL == param_charp)
93 return CURLE_BAD_FUNCTION_ARGUMENT;
96 param_longp = va_arg(arg, long *);
97 if(NULL == param_longp)
98 return CURLE_BAD_FUNCTION_ARGUMENT;
100 case CURLINFO_DOUBLE:
101 param_doublep = va_arg(arg, double *);
102 if(NULL == param_doublep)
103 return CURLE_BAD_FUNCTION_ARGUMENT;
106 param_slistp = va_arg(arg, struct curl_slist **);
107 if(NULL == param_slistp)
108 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_PRETRANSFER_TIME:
141 *param_doublep = data->progress.t_pretransfer;
143 case CURLINFO_STARTTRANSFER_TIME:
144 *param_doublep = data->progress.t_starttransfer;
146 case CURLINFO_SIZE_UPLOAD:
147 *param_doublep = (double)data->progress.uploaded;
149 case CURLINFO_SIZE_DOWNLOAD:
150 *param_doublep = (double)data->progress.downloaded;
152 case CURLINFO_SPEED_DOWNLOAD:
153 *param_doublep = (double)data->progress.dlspeed;
155 case CURLINFO_SPEED_UPLOAD:
156 *param_doublep = (double)data->progress.ulspeed;
158 case CURLINFO_SSL_VERIFYRESULT:
159 *param_longp = data->set.ssl.certverifyresult;
161 case CURLINFO_CONTENT_LENGTH_DOWNLOAD:
162 *param_doublep = (double)data->progress.size_dl;
164 case CURLINFO_CONTENT_LENGTH_UPLOAD:
165 *param_doublep = (double)data->progress.size_ul;
167 case CURLINFO_REDIRECT_TIME:
168 *param_doublep = data->progress.t_redirect;
170 case CURLINFO_REDIRECT_COUNT:
171 *param_longp = data->set.followlocation;
173 case CURLINFO_CONTENT_TYPE:
174 *param_charp = data->info.contenttype;
176 case CURLINFO_PRIVATE:
177 *param_charp = data->set.private_data;
179 case CURLINFO_HTTPAUTH_AVAIL:
180 *param_longp = data->info.httpauthavail;
182 case CURLINFO_PROXYAUTH_AVAIL:
183 *param_longp = data->info.proxyauthavail;
185 case CURLINFO_OS_ERRNO:
186 *param_longp = data->state.os_errno;
188 case CURLINFO_NUM_CONNECTS:
189 *param_longp = data->info.numconnects;
191 case CURLINFO_SSL_ENGINES:
192 *param_slistp = Curl_ssl_engines_list(data);
194 case CURLINFO_COOKIELIST:
195 *param_slistp = Curl_cookie_list(data);
197 case CURLINFO_FTP_ENTRY_PATH:
198 /* Return the entrypath string from the most recent connection.
199 This pointer was copied from the connectdata structure by FTP.
200 The actual string may be free()ed by subsequent libcurl calls so
201 it must be copied to a safer area before the next libcurl call.
202 Callers must never free it themselves. */
203 *param_charp = data->state.most_recent_ftp_entrypath;
205 case CURLINFO_LASTSOCKET:
206 if((data->state.lastconnect != -1) &&
207 (data->state.connc->connects[data->state.lastconnect] != NULL)) {
208 struct connectdata *c = data->state.connc->connects
209 [data->state.lastconnect];
210 *param_longp = c->sock[FIRSTSOCKET];
211 /* we have a socket connected, let's determine if the server shut down */
212 /* determine if ssl */
213 if(c->ssl[FIRSTSOCKET].use) {
214 /* use the SSL context */
215 if (!Curl_ssl_check_cxn(c))
216 *param_longp = -1; /* FIN received */
218 /* Minix 3.1 doesn't support any flags on recv; just assume socket is OK */
222 if(recv((RECV_TYPE_ARG1)c->sock[FIRSTSOCKET], (RECV_TYPE_ARG2)&buf,
223 (RECV_TYPE_ARG3)1, (RECV_TYPE_ARG4)MSG_PEEK) == 0) {
224 *param_longp = -1; /* FIN received */
233 return CURLE_BAD_FUNCTION_ARGUMENT;