adjusted the time-keeping function to work better for location following
[platform/upstream/curl.git] / lib / getinfo.c
1 /*****************************************************************************
2  *                                  _   _ ____  _     
3  *  Project                     ___| | | |  _ \| |    
4  *                             / __| | | | |_) | |    
5  *                            | (__| |_| |  _ <| |___ 
6  *                             \___|\___/|_| \_\_____|
7  *
8  *  The contents of this file are subject to the Mozilla Public License
9  *  Version 1.0 (the "License"); you may not use this file except in
10  *  compliance with the License. You may obtain a copy of the License at
11  *  http://www.mozilla.org/MPL/
12  *
13  *  Software distributed under the License is distributed on an "AS IS"
14  *  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
15  *  License for the specific language governing rights and limitations
16  *  under the License.
17  *
18  *  The Original Code is Curl.
19  *
20  *  The Initial Developer of the Original Code is Daniel Stenberg.
21  *
22  *  Portions created by the Initial Developer are Copyright (C) 1999.
23  *  All Rights Reserved.
24  *
25  * ------------------------------------------------------------
26  * Main author:
27  * - Daniel Stenberg <daniel@haxx.se>
28  *
29  *      http://curl.haxx.se
30  *
31  * $Source$
32  * $Revision$
33  * $Date$
34  * $Author$
35  * $State$
36  * $Locker$
37  *
38  * ------------------------------------------------------------
39  ****************************************************************************/
40
41 #include "setup.h"
42
43 #include <curl/curl.h>
44
45 #include "urldata.h"
46
47 #include <stdio.h>
48 #include <string.h>
49 #include <stdarg.h>
50
51 CURLcode curl_getinfo(CURL *curl, CURLINFO info, ...)
52 {
53   va_list arg;
54   long *param_longp;
55   double *param_doublep;
56   char **param_charp;
57   struct UrlData *data = (struct UrlData *)curl;
58   va_start(arg, info);
59
60   switch(info&CURLINFO_TYPEMASK) {
61   default:
62     return CURLE_BAD_FUNCTION_ARGUMENT;
63   case CURLINFO_STRING:
64     param_charp = va_arg(arg, char **);  
65     if(NULL == param_charp)
66       return CURLE_BAD_FUNCTION_ARGUMENT;
67     break;
68   case CURLINFO_LONG:
69     param_longp = va_arg(arg, long *);
70     if(NULL == param_longp)
71       return CURLE_BAD_FUNCTION_ARGUMENT;
72     break;
73   case CURLINFO_DOUBLE:
74     param_doublep = va_arg(arg, double *);
75     if(NULL == param_doublep)
76       return CURLE_BAD_FUNCTION_ARGUMENT;
77     break;
78   }
79   
80   switch(info) {
81   case CURLINFO_EFFECTIVE_URL:
82     *param_charp = data->url?data->url:"";
83     break;
84   case CURLINFO_HTTP_CODE:
85     *param_longp = data->progress.httpcode;
86     break;
87   case CURLINFO_HEADER_SIZE:
88     *param_longp = data->header_size;
89     break;
90   case CURLINFO_REQUEST_SIZE:
91     *param_longp = data->request_size;
92     break;
93   case CURLINFO_TOTAL_TIME:
94     *param_doublep = data->progress.timespent;
95     break;
96   case CURLINFO_NAMELOOKUP_TIME:
97     *param_doublep = data->progress.t_nslookup;
98     break;
99   case CURLINFO_CONNECT_TIME:
100     *param_doublep = data->progress.t_connect;
101     break;
102   case CURLINFO_PRETRANSFER_TIME:
103     *param_doublep =  data->progress.t_pretransfer;
104     break;
105   case CURLINFO_SIZE_UPLOAD:
106     *param_doublep =  data->progress.uploaded;
107     break;
108   case CURLINFO_SIZE_DOWNLOAD:
109     *param_doublep = data->progress.downloaded;
110     break;
111   case CURLINFO_SPEED_DOWNLOAD:
112     *param_doublep =  data->progress.dlspeed;
113     break;
114   case CURLINFO_SPEED_UPLOAD:
115     *param_doublep = data->progress.ulspeed;
116     break;
117   case CURLINFO_SSL_VERIFYRESULT:
118     *param_longp = data->ssl.certverifyresult;
119     break;
120   default:
121     return CURLE_BAD_FUNCTION_ARGUMENT;
122   }
123   return CURLE_OK;
124 }