Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Utilities / cmcurl-7.19.0 / lib / getinfo.c
blob85214c930b194ac7279f2e6d25651d143dfbbdab
1 /***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
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 ***************************************************************************/
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"
37 #include "connect.h" /* Curl_getconnectinfo() */
39 /* Make this the last #include */
40 #include "memdebug.h"
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;
51 pro->t_nslookup = 0;
52 pro->t_connect = 0;
53 pro->t_pretransfer = 0;
54 pro->t_starttransfer = 0;
55 pro->timespent = 0;
56 pro->t_redirect = 0;
58 info->httpcode = 0;
59 info->httpversion=0;
60 info->filetime=-1; /* -1 is an illegal time and thus means unknown */
62 if(info->contenttype)
63 free(info->contenttype);
64 info->contenttype = NULL;
66 info->header_size = 0;
67 info->request_size = 0;
68 info->numconnects = 0;
69 return CURLE_OK;
72 CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...)
74 va_list arg;
75 long *param_longp=NULL;
76 double *param_doublep=NULL;
77 char **param_charp=NULL;
78 struct curl_slist **param_slistp=NULL;
79 int type;
81 if(!data)
82 return CURLE_BAD_FUNCTION_ARGUMENT;
84 va_start(arg, info);
86 type = CURLINFO_TYPEMASK & (int)info;
87 switch(type) {
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;
108 default:
109 return CURLE_BAD_FUNCTION_ARGUMENT;
112 switch(info) {
113 case CURLINFO_EFFECTIVE_URL:
114 *param_charp = data->change.url?data->change.url:(char *)"";
115 break;
116 case CURLINFO_RESPONSE_CODE:
117 *param_longp = data->info.httpcode;
118 break;
119 case CURLINFO_HTTP_CONNECTCODE:
120 *param_longp = data->info.httpproxycode;
121 break;
122 case CURLINFO_FILETIME:
123 *param_longp = data->info.filetime;
124 break;
125 case CURLINFO_HEADER_SIZE:
126 *param_longp = data->info.header_size;
127 break;
128 case CURLINFO_REQUEST_SIZE:
129 *param_longp = data->info.request_size;
130 break;
131 case CURLINFO_TOTAL_TIME:
132 *param_doublep = data->progress.timespent;
133 break;
134 case CURLINFO_NAMELOOKUP_TIME:
135 *param_doublep = data->progress.t_nslookup;
136 break;
137 case CURLINFO_CONNECT_TIME:
138 *param_doublep = data->progress.t_connect;
139 break;
140 case CURLINFO_APPCONNECT_TIME:
141 *param_doublep = data->progress.t_appconnect;
142 break;
143 case CURLINFO_PRETRANSFER_TIME:
144 *param_doublep = data->progress.t_pretransfer;
145 break;
146 case CURLINFO_STARTTRANSFER_TIME:
147 *param_doublep = data->progress.t_starttransfer;
148 break;
149 case CURLINFO_SIZE_UPLOAD:
150 *param_doublep = (double)data->progress.uploaded;
151 break;
152 case CURLINFO_SIZE_DOWNLOAD:
153 *param_doublep = (double)data->progress.downloaded;
154 break;
155 case CURLINFO_SPEED_DOWNLOAD:
156 *param_doublep = (double)data->progress.dlspeed;
157 break;
158 case CURLINFO_SPEED_UPLOAD:
159 *param_doublep = (double)data->progress.ulspeed;
160 break;
161 case CURLINFO_SSL_VERIFYRESULT:
162 *param_longp = data->set.ssl.certverifyresult;
163 break;
164 case CURLINFO_CONTENT_LENGTH_DOWNLOAD:
165 *param_doublep = (double)data->progress.size_dl;
166 break;
167 case CURLINFO_CONTENT_LENGTH_UPLOAD:
168 *param_doublep = (double)data->progress.size_ul;
169 break;
170 case CURLINFO_REDIRECT_TIME:
171 *param_doublep = data->progress.t_redirect;
172 break;
173 case CURLINFO_REDIRECT_COUNT:
174 *param_longp = data->set.followlocation;
175 break;
176 case CURLINFO_CONTENT_TYPE:
177 *param_charp = data->info.contenttype;
178 break;
179 case CURLINFO_PRIVATE:
180 *param_charp = (char *) data->set.private_data;
181 break;
182 case CURLINFO_HTTPAUTH_AVAIL:
183 *param_longp = data->info.httpauthavail;
184 break;
185 case CURLINFO_PROXYAUTH_AVAIL:
186 *param_longp = data->info.proxyauthavail;
187 break;
188 case CURLINFO_OS_ERRNO:
189 *param_longp = data->state.os_errno;
190 break;
191 case CURLINFO_NUM_CONNECTS:
192 *param_longp = data->info.numconnects;
193 break;
194 case CURLINFO_SSL_ENGINES:
195 *param_slistp = Curl_ssl_engines_list(data);
196 break;
197 case CURLINFO_COOKIELIST:
198 *param_slistp = Curl_cookie_list(data);
199 break;
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;
207 break;
208 case CURLINFO_LASTSOCKET:
209 (void)Curl_getconnectinfo(data, param_longp, NULL);
210 break;
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;
215 break;
216 case CURLINFO_PRIMARY_IP:
217 /* Return the ip address of the most recent (primary) connection */
218 *param_charp = data->info.ip;
219 break;
220 default:
221 return CURLE_BAD_FUNCTION_ARGUMENT;
223 return CURLE_OK;