00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "tool_setup.h"
00023
00024 #ifdef USE_ENVIRONMENT
00025
00026 #ifdef __riscos__
00027 # include <kernel.h>
00028 #endif
00029
00030 #include <curl/mprintf.h>
00031 #include "tool_writeenv.h"
00032 #include "memdebug.h"
00033
00034 static const struct
00035 {
00036 const char *name;
00037 CURLINFO id;
00038 enum {
00039 writeenv_NONE,
00040 writeenv_DOUBLE,
00041 writeenv_LONG,
00042 writeenv_STRING
00043 } type;
00044 } variables[14] =
00045 {
00046 {"curl_url_effective", CURLINFO_EFFECTIVE_URL, writeenv_STRING},
00047 {"curl_http_code", CURLINFO_RESPONSE_CODE, writeenv_LONG},
00048 {"curl_time_total", CURLINFO_TOTAL_TIME, writeenv_DOUBLE},
00049 {"curl_time_namelookup", CURLINFO_NAMELOOKUP_TIME, writeenv_DOUBLE},
00050 {"curl_time_connect", CURLINFO_CONNECT_TIME, writeenv_DOUBLE},
00051 {"curl_time_pretransfer", CURLINFO_PRETRANSFER_TIME, writeenv_DOUBLE},
00052 {"curl_time_starttransfer", CURLINFO_STARTTRANSFER_TIME, writeenv_DOUBLE},
00053 {"curl_size_header", CURLINFO_HEADER_SIZE, writeenv_LONG},
00054 {"curl_size_request", CURLINFO_REQUEST_SIZE, writeenv_LONG},
00055 {"curl_size_download", CURLINFO_SIZE_DOWNLOAD, writeenv_DOUBLE},
00056 {"curl_size_upload", CURLINFO_SIZE_UPLOAD, writeenv_DOUBLE},
00057 {"curl_speed_download", CURLINFO_SPEED_DOWNLOAD, writeenv_DOUBLE},
00058 {"curl_speed_upload", CURLINFO_SPEED_UPLOAD, writeenv_DOUBLE},
00059 {NULL, 0, writeenv_NONE}
00060 };
00061
00062 static void internalSetEnv(const char *name, char *value)
00063 {
00064
00065 #ifdef __riscos__
00066 _kernel_setenv(name, value);
00067 #elif defined (CURLDEBUG)
00068 curl_memlog("ENV %s = %s\n", name, value);
00069 #endif
00070 return;
00071 }
00072
00073 void ourWriteEnv(CURL *curl)
00074 {
00075 unsigned int i;
00076 char *string, numtext[10];
00077 long longinfo;
00078 double doubleinfo;
00079
00080 for(i=0; variables[i].name; i++) {
00081 switch(variables[i].type) {
00082 case writeenv_STRING:
00083 if(curl_easy_getinfo(curl, variables[i].id, &string) == CURLE_OK)
00084 internalSetEnv(variables[i].name, string);
00085 else
00086 internalSetEnv(variables[i].name, NULL);
00087 break;
00088
00089 case writeenv_LONG:
00090 if(curl_easy_getinfo(curl, variables[i].id, &longinfo) == CURLE_OK) {
00091 curl_msprintf(numtext, "%5ld", longinfo);
00092 internalSetEnv(variables[i].name, numtext);
00093 }
00094 else
00095 internalSetEnv(variables[i].name, NULL);
00096 break;
00097 case writeenv_DOUBLE:
00098 if(curl_easy_getinfo(curl, variables[i].id, &doubleinfo) == CURLE_OK) {
00099 curl_msprintf(numtext, "%6.2f", doubleinfo);
00100 internalSetEnv(variables[i].name, numtext);
00101 }
00102 else
00103 internalSetEnv(variables[i].name, NULL);
00104 break;
00105 default:
00106 break;
00107 }
00108 }
00109
00110 return;
00111 }
00112
00113 #endif