CURLINFO_NUM_CONNECTS and more
[platform/upstream/curl.git] / lib / getinfo.c
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2004, 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 #include "getinfo.h"
30
31 #include <stdio.h>
32 #include <string.h>
33 #include <stdarg.h>
34 #include <stdlib.h>
35 #include "memory.h"
36
37 /* Make this the last #include */
38 #include "memdebug.h"
39
40 /*
41  * This is supposed to be called in the beginning of a perform() session
42  * and should reset all session-info variables
43  */
44 CURLcode Curl_initinfo(struct SessionHandle *data)
45 {
46   struct Progress *pro = &data->progress;
47   struct PureInfo *info =&data->info;
48
49   pro->t_nslookup = 0;
50   pro->t_connect = 0;
51   pro->t_pretransfer = 0;
52   pro->t_starttransfer = 0;
53   pro->timespent = 0;
54   pro->t_redirect = 0;
55
56   info->httpcode = 0;
57   info->httpversion=0;
58   info->filetime=-1; /* -1 is an illegal time and thus means unknown */
59
60   if (info->contenttype)
61     free(info->contenttype);
62   info->contenttype = NULL;
63
64   info->header_size = 0;
65   info->request_size = 0;
66   info->numconnects = 0;
67   return CURLE_OK;
68 }
69
70 CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...)
71 {
72   va_list arg;
73   long *param_longp=NULL;
74   double *param_doublep=NULL;
75   char **param_charp=NULL;
76   va_start(arg, info);
77
78   switch(info&CURLINFO_TYPEMASK) {
79   default:
80     return CURLE_BAD_FUNCTION_ARGUMENT;
81   case CURLINFO_STRING:
82     param_charp = va_arg(arg, char **);
83     if(NULL == param_charp)
84       return CURLE_BAD_FUNCTION_ARGUMENT;
85     break;
86   case CURLINFO_LONG:
87     param_longp = va_arg(arg, long *);
88     if(NULL == param_longp)
89       return CURLE_BAD_FUNCTION_ARGUMENT;
90     break;
91   case CURLINFO_DOUBLE:
92     param_doublep = va_arg(arg, double *);
93     if(NULL == param_doublep)
94       return CURLE_BAD_FUNCTION_ARGUMENT;
95     break;
96   }
97
98   switch(info) {
99   case CURLINFO_EFFECTIVE_URL:
100     *param_charp = data->change.url?data->change.url:(char *)"";
101     break;
102   case CURLINFO_RESPONSE_CODE:
103     *param_longp = data->info.httpcode;
104     break;
105   case CURLINFO_HTTP_CONNECTCODE:
106     *param_longp = data->info.httpproxycode;
107     break;
108   case CURLINFO_FILETIME:
109     *param_longp = data->info.filetime;
110     break;
111   case CURLINFO_HEADER_SIZE:
112     *param_longp = data->info.header_size;
113     break;
114   case CURLINFO_REQUEST_SIZE:
115     *param_longp = data->info.request_size;
116     break;
117   case CURLINFO_TOTAL_TIME:
118     *param_doublep = data->progress.timespent;
119     break;
120   case CURLINFO_NAMELOOKUP_TIME:
121     *param_doublep = data->progress.t_nslookup;
122     break;
123   case CURLINFO_CONNECT_TIME:
124     *param_doublep = data->progress.t_connect;
125     break;
126   case CURLINFO_PRETRANSFER_TIME:
127     *param_doublep =  data->progress.t_pretransfer;
128     break;
129   case CURLINFO_STARTTRANSFER_TIME:
130     *param_doublep = data->progress.t_starttransfer;
131     break;
132   case CURLINFO_SIZE_UPLOAD:
133     *param_doublep =  (double)data->progress.uploaded;
134     break;
135   case CURLINFO_SIZE_DOWNLOAD:
136     *param_doublep = (double)data->progress.downloaded;
137     break;
138   case CURLINFO_SPEED_DOWNLOAD:
139     *param_doublep =  (double)data->progress.dlspeed;
140     break;
141   case CURLINFO_SPEED_UPLOAD:
142     *param_doublep = (double)data->progress.ulspeed;
143     break;
144   case CURLINFO_SSL_VERIFYRESULT:
145     *param_longp = data->set.ssl.certverifyresult;
146     break;
147   case CURLINFO_CONTENT_LENGTH_DOWNLOAD:
148     *param_doublep = (double)data->progress.size_dl;
149     break;
150   case CURLINFO_CONTENT_LENGTH_UPLOAD:
151     *param_doublep = (double)data->progress.size_ul;
152     break;
153   case CURLINFO_REDIRECT_TIME:
154     *param_doublep =  data->progress.t_redirect;
155     break;
156   case CURLINFO_REDIRECT_COUNT:
157     *param_longp = data->set.followlocation;
158     break;
159   case CURLINFO_CONTENT_TYPE:
160     *param_charp = data->info.contenttype;
161     break;
162   case CURLINFO_PRIVATE:
163     *param_charp = data->set.private;
164     break;
165   case CURLINFO_HTTPAUTH_AVAIL:
166     *param_longp = data->info.httpauthavail;
167     break;
168   case CURLINFO_PROXYAUTH_AVAIL:
169     *param_longp = data->info.proxyauthavail;
170     break;
171   case CURLINFO_OS_ERRNO:
172     *param_longp = data->state.os_errno;
173     break;
174   case CURLINFO_NUM_CONNECTS:
175     *param_longp = data->info.numconnects;
176     break;
177   default:
178     return CURLE_BAD_FUNCTION_ARGUMENT;
179   }
180   return CURLE_OK;
181 }