~ubuntu-branches/ubuntu/lucid/curl/lucid-201101212007

« back to all changes in this revision

Viewing changes to lib/getinfo.c

  • Committer: Bazaar Package Importer
  • Author(s): Domenico Andreoli
  • Date: 2002-03-12 19:06:21 UTC
  • Revision ID: james.westby@ubuntu.com-20020312190621-iqx7k9cipo5d0ifr
Tags: upstream-7.9.5
ImportĀ upstreamĀ versionĀ 7.9.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 *                                  _   _ ____  _     
 
3
 *  Project                     ___| | | |  _ \| |    
 
4
 *                             / __| | | | |_) | |    
 
5
 *                            | (__| |_| |  _ <| |___ 
 
6
 *                             \___|\___/|_| \_\_____|
 
7
 *
 
8
 * Copyright (C) 2000, Daniel Stenberg, <daniel@haxx.se>, et al.
 
9
 *
 
10
 * In order to be useful for every potential user, curl and libcurl are
 
11
 * dual-licensed under the MPL and the MIT/X-derivate licenses.
 
12
 *
 
13
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
 
14
 * copies of the Software, and permit persons to whom the Software is
 
15
 * furnished to do so, under the terms of the MPL or the MIT/X-derivate
 
16
 * licenses. You may pick one of these licenses.
 
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.18 2002/02/20 13:46:54 bagder Exp $
 
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
/*
 
39
 * This is supposed to be called in the beginning of a permform() session
 
40
 * and should reset all session-info variables
 
41
 */
 
42
CURLcode Curl_initinfo(struct SessionHandle *data)
 
43
{
 
44
  struct Progress *pro = &data->progress;
 
45
  struct PureInfo *info =&data->info;
 
46
 
 
47
  pro->t_nslookup = 0;
 
48
  pro->t_connect = 0;
 
49
  pro->t_pretransfer = 0;
 
50
  pro->t_starttransfer = 0;
 
51
  pro->timespent = 0;
 
52
 
 
53
  info->httpcode = 0;
 
54
  info->httpversion=0;
 
55
  info->filetime=-1; /* -1 is an illegal time and thus means unknown */
 
56
  
 
57
  if (info->contenttype)
 
58
    free(info->contenttype);
 
59
  info->contenttype = NULL;
 
60
 
 
61
  info->header_size = 0;
 
62
  info->request_size = 0;
 
63
  return CURLE_OK;
 
64
}
 
65
 
 
66
CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...)
 
67
{
 
68
  va_list arg;
 
69
  long *param_longp;
 
70
  double *param_doublep;
 
71
  char **param_charp;
 
72
  va_start(arg, info);
 
73
 
 
74
  switch(info&CURLINFO_TYPEMASK) {
 
75
  default:
 
76
    return CURLE_BAD_FUNCTION_ARGUMENT;
 
77
  case CURLINFO_STRING:
 
78
    param_charp = va_arg(arg, char **);  
 
79
    if(NULL == param_charp)
 
80
      return CURLE_BAD_FUNCTION_ARGUMENT;
 
81
    break;
 
82
  case CURLINFO_LONG:
 
83
    param_longp = va_arg(arg, long *);
 
84
    if(NULL == param_longp)
 
85
      return CURLE_BAD_FUNCTION_ARGUMENT;
 
86
    break;
 
87
  case CURLINFO_DOUBLE:
 
88
    param_doublep = va_arg(arg, double *);
 
89
    if(NULL == param_doublep)
 
90
      return CURLE_BAD_FUNCTION_ARGUMENT;
 
91
    break;
 
92
  }
 
93
  
 
94
  switch(info) {
 
95
  case CURLINFO_EFFECTIVE_URL:
 
96
    *param_charp = data->change.url?data->change.url:(char *)"";
 
97
    break;
 
98
  case CURLINFO_HTTP_CODE:
 
99
    *param_longp = data->info.httpcode;
 
100
    break;
 
101
  case CURLINFO_FILETIME:
 
102
    *param_longp = data->info.filetime;
 
103
    break;
 
104
  case CURLINFO_HEADER_SIZE:
 
105
    *param_longp = data->info.header_size;
 
106
    break;
 
107
  case CURLINFO_REQUEST_SIZE:
 
108
    *param_longp = data->info.request_size;
 
109
    break;
 
110
  case CURLINFO_TOTAL_TIME:
 
111
    *param_doublep = data->progress.timespent;
 
112
    break;
 
113
  case CURLINFO_NAMELOOKUP_TIME:
 
114
    *param_doublep = data->progress.t_nslookup;
 
115
    break;
 
116
  case CURLINFO_CONNECT_TIME:
 
117
    *param_doublep = data->progress.t_connect;
 
118
    break;
 
119
  case CURLINFO_PRETRANSFER_TIME:
 
120
    *param_doublep =  data->progress.t_pretransfer;
 
121
    break;
 
122
  case CURLINFO_STARTTRANSFER_TIME:
 
123
    *param_doublep = data->progress.t_starttransfer;
 
124
    break;
 
125
  case CURLINFO_SIZE_UPLOAD:
 
126
    *param_doublep =  data->progress.uploaded;
 
127
    break;
 
128
  case CURLINFO_SIZE_DOWNLOAD:
 
129
    *param_doublep = data->progress.downloaded;
 
130
    break;
 
131
  case CURLINFO_SPEED_DOWNLOAD:
 
132
    *param_doublep =  data->progress.dlspeed;
 
133
    break;
 
134
  case CURLINFO_SPEED_UPLOAD:
 
135
    *param_doublep = data->progress.ulspeed;
 
136
    break;
 
137
  case CURLINFO_SSL_VERIFYRESULT:
 
138
    *param_longp = data->set.ssl.certverifyresult;
 
139
    break;
 
140
  case CURLINFO_CONTENT_LENGTH_DOWNLOAD:
 
141
    *param_doublep = data->progress.size_dl;
 
142
    break;
 
143
  case CURLINFO_CONTENT_LENGTH_UPLOAD:
 
144
    *param_doublep = data->progress.size_ul;
 
145
    break;
 
146
  case CURLINFO_CONTENT_TYPE:
 
147
    *param_charp = data->info.contenttype;
 
148
    break;
 
149
  default:
 
150
    return CURLE_BAD_FUNCTION_ARGUMENT;
 
151
  }
 
152
  return CURLE_OK;
 
153
}
 
154
 
 
155
/*
 
156
 * local variables:
 
157
 * eval: (load-file "../curl-mode.el")
 
158
 * end:
 
159
 * vim600: fdm=marker
 
160
 * vim: et sw=2 ts=2 sts=2 tw=78
 
161
 */