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