~ubuntu-branches/ubuntu/warty/curl/warty-security

« back to all changes in this revision

Viewing changes to src/writeenv.c

  • Committer: Bazaar Package Importer
  • Author(s): Domenico Andreoli
  • Date: 2004-06-04 19:09:25 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040604190925-wy048bp31320r2z6
Tags: 7.12.0.is.7.11.2-1
* Reverted to version 7.11.2 (closes: #252348).
* Disabled support for libidn (closes: #252367). This is to leave
  curl in unstable as much similar as possible to the one in testing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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: writeenv.c,v 1.8 2004/03/29 12:29:26 bagder Exp $
 
22
 ***************************************************************************/
 
23
 
 
24
#include "setup.h"
 
25
 
 
26
#ifdef USE_ENVIRONMENT
 
27
 
 
28
#include <curl/curl.h>
 
29
 
 
30
#ifdef __riscos__
 
31
#include <kernel.h>
 
32
#endif
 
33
 
 
34
struct
 
35
{
 
36
  const char * name;
 
37
  CURLINFO id;
 
38
  enum {
 
39
    writeenv_NONE,
 
40
    writeenv_DOUBLE,
 
41
    writeenv_LONG,
 
42
    writeenv_STRING
 
43
  } type;
 
44
} variables[14] =
 
45
{
 
46
  {"curl_url_effective", CURLINFO_EFFECTIVE_URL, writeenv_STRING},
 
47
  {"curl_http_code", CURLINFO_RESPONSE_CODE, writeenv_LONG},
 
48
  {"curl_time_total", CURLINFO_TOTAL_TIME, writeenv_DOUBLE},
 
49
  {"curl_time_namelookup", CURLINFO_NAMELOOKUP_TIME, writeenv_DOUBLE},
 
50
  {"curl_time_connect", CURLINFO_CONNECT_TIME, writeenv_DOUBLE},
 
51
  {"curl_time_pretransfer", CURLINFO_PRETRANSFER_TIME, writeenv_DOUBLE},
 
52
  {"curl_time_starttransfer", CURLINFO_STARTTRANSFER_TIME, writeenv_DOUBLE},
 
53
  {"curl_size_header", CURLINFO_HEADER_SIZE, writeenv_LONG},
 
54
  {"curl_size_request", CURLINFO_REQUEST_SIZE, writeenv_LONG},
 
55
  {"curl_size_download", CURLINFO_SIZE_DOWNLOAD, writeenv_DOUBLE},
 
56
  {"curl_size_upload", CURLINFO_SIZE_UPLOAD, writeenv_DOUBLE},
 
57
  {"curl_speed_download", CURLINFO_SPEED_DOWNLOAD, writeenv_DOUBLE},
 
58
  {"curl_speed_upload", CURLINFO_SPEED_UPLOAD, writeenv_DOUBLE},
 
59
  {NULL, 0, writeenv_NONE}
 
60
 };
 
61
 
 
62
static void internalSetEnv(const char * name, char * value)
 
63
{
 
64
  /* Add your OS-specific code here. */
 
65
#ifdef __riscos__
 
66
  _kernel_setenv(name, value);
 
67
#elif defined (CURLDEBUG)
 
68
  extern FILE *curl_debuglogfile;
 
69
  if (curl_debuglogfile)
 
70
     fprintf (curl_debuglogfile, "ENV %s = %s\n", name, value);
 
71
#endif
 
72
  return;
 
73
}
 
74
 
 
75
void ourWriteEnv(CURL *curl)
 
76
{
 
77
  unsigned int i;
 
78
  char *string, numtext[10];
 
79
  long longinfo;
 
80
  double doubleinfo;
 
81
  
 
82
  for (i=0; variables[i].name; i++) {
 
83
    switch (variables[i].type) {
 
84
    case writeenv_STRING:
 
85
      if (curl_easy_getinfo(curl, variables[i].id, &string) == CURLE_OK)
 
86
        internalSetEnv(variables[i].name, string);
 
87
      else
 
88
        internalSetEnv(variables[i].name, NULL);
 
89
      break;
 
90
 
 
91
    case writeenv_LONG:
 
92
      if (curl_easy_getinfo(curl, variables[i].id, &longinfo) == CURLE_OK) {
 
93
        sprintf(numtext, "%5ld", longinfo);
 
94
        internalSetEnv(variables[i].name, numtext);
 
95
      }
 
96
      else
 
97
        internalSetEnv(variables[i].name, NULL);
 
98
      break;
 
99
    case writeenv_DOUBLE:
 
100
      if (curl_easy_getinfo(curl, variables[i].id, &doubleinfo) == CURLE_OK) {
 
101
        sprintf(numtext, "%6.2f", doubleinfo);
 
102
        internalSetEnv(variables[i].name, numtext);
 
103
      }
 
104
      else
 
105
        internalSetEnv(variables[i].name, NULL);
 
106
      break;
 
107
    default:
 
108
      break;
 
109
    }
 
110
  }
 
111
 
 
112
  return;
 
113
}
 
114
 
 
115
#endif