Update tag value for tizen 2.0 build
[external/curl.git] / src / writeenv.c
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2010, 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  ***************************************************************************/
22
23 #include "setup.h"
24
25 #ifdef USE_ENVIRONMENT
26
27 #include <curl/curl.h>
28 #include "writeenv.h"
29
30 #ifdef __riscos__
31 #include <kernel.h>
32 #endif
33
34 #define _MPRINTF_REPLACE /* use our functions only */
35 #include <curl/mprintf.h>
36
37 #if defined(CURLDEBUG) && defined(CURLTOOLDEBUG)
38 #include "memdebug.h"
39 #endif
40
41 static const struct
42 {
43   const char * name;
44   CURLINFO id;
45   enum {
46     writeenv_NONE,
47     writeenv_DOUBLE,
48     writeenv_LONG,
49     writeenv_STRING
50   } type;
51 } variables[14] =
52 {
53   {"curl_url_effective", CURLINFO_EFFECTIVE_URL, writeenv_STRING},
54   {"curl_http_code", CURLINFO_RESPONSE_CODE, writeenv_LONG},
55   {"curl_time_total", CURLINFO_TOTAL_TIME, writeenv_DOUBLE},
56   {"curl_time_namelookup", CURLINFO_NAMELOOKUP_TIME, writeenv_DOUBLE},
57   {"curl_time_connect", CURLINFO_CONNECT_TIME, writeenv_DOUBLE},
58   {"curl_time_pretransfer", CURLINFO_PRETRANSFER_TIME, writeenv_DOUBLE},
59   {"curl_time_starttransfer", CURLINFO_STARTTRANSFER_TIME, writeenv_DOUBLE},
60   {"curl_size_header", CURLINFO_HEADER_SIZE, writeenv_LONG},
61   {"curl_size_request", CURLINFO_REQUEST_SIZE, writeenv_LONG},
62   {"curl_size_download", CURLINFO_SIZE_DOWNLOAD, writeenv_DOUBLE},
63   {"curl_size_upload", CURLINFO_SIZE_UPLOAD, writeenv_DOUBLE},
64   {"curl_speed_download", CURLINFO_SPEED_DOWNLOAD, writeenv_DOUBLE},
65   {"curl_speed_upload", CURLINFO_SPEED_UPLOAD, writeenv_DOUBLE},
66   {NULL, 0, writeenv_NONE}
67  };
68
69 static void internalSetEnv(const char * name, char * value)
70 {
71   /* Add your OS-specific code here. */
72 #ifdef __riscos__
73   _kernel_setenv(name, value);
74 #elif defined (CURLDEBUG)
75   curl_memlog("ENV %s = %s\n", name, value);
76 #endif
77   return;
78 }
79
80 void ourWriteEnv(CURL *curl)
81 {
82   unsigned int i;
83   char *string, numtext[10];
84   long longinfo;
85   double doubleinfo;
86
87   for (i=0; variables[i].name; i++) {
88     switch (variables[i].type) {
89     case writeenv_STRING:
90       if (curl_easy_getinfo(curl, variables[i].id, &string) == CURLE_OK)
91         internalSetEnv(variables[i].name, string);
92       else
93         internalSetEnv(variables[i].name, NULL);
94       break;
95
96     case writeenv_LONG:
97       if (curl_easy_getinfo(curl, variables[i].id, &longinfo) == CURLE_OK) {
98         curl_msprintf(numtext, "%5ld", longinfo);
99         internalSetEnv(variables[i].name, numtext);
100       }
101       else
102         internalSetEnv(variables[i].name, NULL);
103       break;
104     case writeenv_DOUBLE:
105       if (curl_easy_getinfo(curl, variables[i].id, &doubleinfo) == CURLE_OK) {
106         curl_msprintf(numtext, "%6.2f", doubleinfo);
107         internalSetEnv(variables[i].name, numtext);
108       }
109       else
110         internalSetEnv(variables[i].name, NULL);
111       break;
112     default:
113       break;
114     }
115   }
116
117   return;
118 }
119
120 #endif