9bd737020ebdd0852b53fabe2782af2dbe2b938e
[platform/upstream/curl.git] / lib / getinfo.c
1 /***************************************************************************
2  *                                  _   _ ____  _     
3  *  Project                     ___| | | |  _ \| |    
4  *                             / __| | | | |_) | |    
5  *                            | (__| |_| |  _ <| |___ 
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2003, Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
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.
13  * 
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.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  * $Id$
22  ***************************************************************************/
23
24 #include "setup.h"
25
26 #include <curl/curl.h>
27
28 #include "urldata.h"
29
30 #include <stdio.h>
31 #include <string.h>
32 #include <stdarg.h>
33
34 #ifdef  VMS
35 #include        <stdlib.h>
36 #endif
37
38 /* Make this the last #include */
39 #ifdef CURLDEBUG
40 #include "memdebug.h"
41 #else
42 #include <stdlib.h>
43 #endif
44
45 /*
46  * This is supposed to be called in the beginning of a permform() session
47  * and should reset all session-info variables
48  */
49 CURLcode Curl_initinfo(struct SessionHandle *data)
50 {
51   struct Progress *pro = &data->progress;
52   struct PureInfo *info =&data->info;
53
54   pro->t_nslookup = 0;
55   pro->t_connect = 0;
56   pro->t_pretransfer = 0;
57   pro->t_starttransfer = 0;
58   pro->timespent = 0;
59   pro->t_redirect = 0;
60
61   info->httpcode = 0;
62   info->httpversion=0;
63   info->filetime=-1; /* -1 is an illegal time and thus means unknown */
64   
65   if (info->contenttype)
66     free(info->contenttype);
67   info->contenttype = NULL;
68
69   info->header_size = 0;
70   info->request_size = 0;
71   return CURLE_OK;
72 }
73
74 CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...)
75 {
76   va_list arg;
77   long *param_longp=NULL;
78   double *param_doublep=NULL;
79   char **param_charp=NULL;
80   va_start(arg, info);
81
82   switch(info&CURLINFO_TYPEMASK) {
83   default:
84     return CURLE_BAD_FUNCTION_ARGUMENT;
85   case CURLINFO_STRING:
86     param_charp = va_arg(arg, char **);  
87     if(NULL == param_charp)
88       return CURLE_BAD_FUNCTION_ARGUMENT;
89     break;
90   case CURLINFO_LONG:
91     param_longp = va_arg(arg, long *);
92     if(NULL == param_longp)
93       return CURLE_BAD_FUNCTION_ARGUMENT;
94     break;
95   case CURLINFO_DOUBLE:
96     param_doublep = va_arg(arg, double *);
97     if(NULL == param_doublep)
98       return CURLE_BAD_FUNCTION_ARGUMENT;
99     break;
100   }
101   
102   switch(info) {
103   case CURLINFO_EFFECTIVE_URL:
104     *param_charp = data->change.url?data->change.url:(char *)"";
105     break;
106   case CURLINFO_HTTP_CODE:
107     *param_longp = data->info.httpcode;
108     break;
109   case CURLINFO_FILETIME:
110     *param_longp = data->info.filetime;
111     break;
112   case CURLINFO_HEADER_SIZE:
113     *param_longp = data->info.header_size;
114     break;
115   case CURLINFO_REQUEST_SIZE:
116     *param_longp = data->info.request_size;
117     break;
118   case CURLINFO_TOTAL_TIME:
119     *param_doublep = data->progress.timespent;
120     break;
121   case CURLINFO_NAMELOOKUP_TIME:
122     *param_doublep = data->progress.t_nslookup;
123     break;
124   case CURLINFO_CONNECT_TIME:
125     *param_doublep = data->progress.t_connect;
126     break;
127   case CURLINFO_PRETRANSFER_TIME:
128     *param_doublep =  data->progress.t_pretransfer;
129     break;
130   case CURLINFO_STARTTRANSFER_TIME:
131     *param_doublep = data->progress.t_starttransfer;
132     break;
133   case CURLINFO_SIZE_UPLOAD:
134     *param_doublep =  data->progress.uploaded;
135     break;
136   case CURLINFO_SIZE_DOWNLOAD:
137     *param_doublep = data->progress.downloaded;
138     break;
139   case CURLINFO_SPEED_DOWNLOAD:
140     *param_doublep =  data->progress.dlspeed;
141     break;
142   case CURLINFO_SPEED_UPLOAD:
143     *param_doublep = data->progress.ulspeed;
144     break;
145   case CURLINFO_SSL_VERIFYRESULT:
146     *param_longp = data->set.ssl.certverifyresult;
147     break;
148   case CURLINFO_CONTENT_LENGTH_DOWNLOAD:
149     *param_doublep = data->progress.size_dl;
150     break;
151   case CURLINFO_CONTENT_LENGTH_UPLOAD:
152     *param_doublep = data->progress.size_ul;
153     break;
154   case CURLINFO_REDIRECT_TIME:
155     *param_doublep =  data->progress.t_redirect;
156     break;
157   case CURLINFO_REDIRECT_COUNT:
158     *param_longp = data->set.followlocation;
159     break;
160   case CURLINFO_CONTENT_TYPE:
161     *param_charp = data->info.contenttype;
162     break;
163   case CURLINFO_PRIVATE:
164     *param_charp = data->set.private;
165     break;
166   default:
167     return CURLE_BAD_FUNCTION_ARGUMENT;
168   }
169   return CURLE_OK;
170 }