Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Utilities / cmcurl / getinfo.c
blobb672cff31746383b77d46f98e13fb5f1ef77c281
1 /***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
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 ***************************************************************************/
24 #include "setup.h"
26 #include <curl/curl.h>
28 #include "urldata.h"
29 #include "getinfo.h"
31 #include <stdio.h>
32 #include <string.h>
33 #include <stdarg.h>
34 #include <stdlib.h>
35 #include "memory.h"
36 #include "sslgen.h"
38 /* Make this the last #include */
39 #include "memdebug.h"
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;
50 pro->t_nslookup = 0;
51 pro->t_connect = 0;
52 pro->t_pretransfer = 0;
53 pro->t_starttransfer = 0;
54 pro->timespent = 0;
55 pro->t_redirect = 0;
57 info->httpcode = 0;
58 info->httpversion=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;
68 return CURLE_OK;
71 CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...)
73 va_list arg;
74 long *param_longp=NULL;
75 double *param_doublep=NULL;
76 char **param_charp=NULL;
77 struct curl_slist **param_slistp=NULL;
78 char buf;
80 if(!data)
81 return CURLE_BAD_FUNCTION_ARGUMENT;
83 va_start(arg, info);
85 switch(info&CURLINFO_TYPEMASK) {
86 default:
87 return CURLE_BAD_FUNCTION_ARGUMENT;
88 case CURLINFO_STRING:
89 param_charp = va_arg(arg, char **);
90 if(NULL == param_charp)
91 return CURLE_BAD_FUNCTION_ARGUMENT;
92 break;
93 case CURLINFO_LONG:
94 param_longp = va_arg(arg, long *);
95 if(NULL == param_longp)
96 return CURLE_BAD_FUNCTION_ARGUMENT;
97 break;
98 case CURLINFO_DOUBLE:
99 param_doublep = va_arg(arg, double *);
100 if(NULL == param_doublep)
101 return CURLE_BAD_FUNCTION_ARGUMENT;
102 break;
103 case CURLINFO_SLIST:
104 param_slistp = va_arg(arg, struct curl_slist **);
105 if(NULL == param_slistp)
106 return CURLE_BAD_FUNCTION_ARGUMENT;
107 break;
110 switch(info) {
111 case CURLINFO_EFFECTIVE_URL:
112 *param_charp = data->change.url?data->change.url:(char *)"";
113 break;
114 case CURLINFO_RESPONSE_CODE:
115 *param_longp = data->info.httpcode;
116 break;
117 case CURLINFO_HTTP_CONNECTCODE:
118 *param_longp = data->info.httpproxycode;
119 break;
120 case CURLINFO_FILETIME:
121 *param_longp = data->info.filetime;
122 break;
123 case CURLINFO_HEADER_SIZE:
124 *param_longp = data->info.header_size;
125 break;
126 case CURLINFO_REQUEST_SIZE:
127 *param_longp = data->info.request_size;
128 break;
129 case CURLINFO_TOTAL_TIME:
130 *param_doublep = data->progress.timespent;
131 break;
132 case CURLINFO_NAMELOOKUP_TIME:
133 *param_doublep = data->progress.t_nslookup;
134 break;
135 case CURLINFO_CONNECT_TIME:
136 *param_doublep = data->progress.t_connect;
137 break;
138 case CURLINFO_PRETRANSFER_TIME:
139 *param_doublep = data->progress.t_pretransfer;
140 break;
141 case CURLINFO_STARTTRANSFER_TIME:
142 *param_doublep = data->progress.t_starttransfer;
143 break;
144 case CURLINFO_SIZE_UPLOAD:
145 *param_doublep = (double)data->progress.uploaded;
146 break;
147 case CURLINFO_SIZE_DOWNLOAD:
148 *param_doublep = (double)data->progress.downloaded;
149 break;
150 case CURLINFO_SPEED_DOWNLOAD:
151 *param_doublep = (double)data->progress.dlspeed;
152 break;
153 case CURLINFO_SPEED_UPLOAD:
154 *param_doublep = (double)data->progress.ulspeed;
155 break;
156 case CURLINFO_SSL_VERIFYRESULT:
157 *param_longp = data->set.ssl.certverifyresult;
158 break;
159 case CURLINFO_CONTENT_LENGTH_DOWNLOAD:
160 *param_doublep = (double)data->progress.size_dl;
161 break;
162 case CURLINFO_CONTENT_LENGTH_UPLOAD:
163 *param_doublep = (double)data->progress.size_ul;
164 break;
165 case CURLINFO_REDIRECT_TIME:
166 *param_doublep = data->progress.t_redirect;
167 break;
168 case CURLINFO_REDIRECT_COUNT:
169 *param_longp = data->set.followlocation;
170 break;
171 case CURLINFO_CONTENT_TYPE:
172 *param_charp = data->info.contenttype;
173 break;
174 case CURLINFO_PRIVATE:
175 *param_charp = data->set.private_data;
176 break;
177 case CURLINFO_HTTPAUTH_AVAIL:
178 *param_longp = data->info.httpauthavail;
179 break;
180 case CURLINFO_PROXYAUTH_AVAIL:
181 *param_longp = data->info.proxyauthavail;
182 break;
183 case CURLINFO_OS_ERRNO:
184 *param_longp = data->state.os_errno;
185 break;
186 case CURLINFO_NUM_CONNECTS:
187 *param_longp = data->info.numconnects;
188 break;
189 case CURLINFO_SSL_ENGINES:
190 *param_slistp = Curl_ssl_engines_list(data);
191 break;
192 case CURLINFO_COOKIELIST:
193 *param_slistp = Curl_cookie_list(data);
194 break;
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;
202 break;
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 */
217 #ifdef MSG_PEEK
218 else {
219 /* use the socket */
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 */
225 #endif
227 else
228 *param_longp = -1;
229 break;
230 default:
231 return CURLE_BAD_FUNCTION_ARGUMENT;
233 return CURLE_OK;