2002-09-03 07:52:59 -04:00
|
|
|
/***************************************************************************
|
2008-11-03 10:51:40 -05:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
2002-04-08 18:40:38 -04:00
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2010-01-18 15:22:04 -05:00
|
|
|
* Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2002-04-08 18:40:38 -04:00
|
|
|
*
|
2002-09-03 07:52:59 -04:00
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
|
|
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
2008-11-03 10:51:40 -05:00
|
|
|
*
|
2002-04-08 18:40:38 -04:00
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
2002-09-03 07:52:59 -04:00
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
2002-04-08 18:40:38 -04:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
2002-09-03 07:52:59 -04:00
|
|
|
***************************************************************************/
|
2002-04-08 18:40:38 -04:00
|
|
|
|
|
|
|
#include "setup.h"
|
2002-04-08 18:51:21 -04:00
|
|
|
|
|
|
|
#ifdef USE_ENVIRONMENT
|
|
|
|
|
2002-04-08 18:40:38 -04:00
|
|
|
#include <curl/curl.h>
|
2004-12-14 20:38:25 -05:00
|
|
|
#include "writeenv.h"
|
2002-04-08 18:40:38 -04:00
|
|
|
|
|
|
|
#ifdef __riscos__
|
|
|
|
#include <kernel.h>
|
|
|
|
#endif
|
|
|
|
|
2008-10-25 12:15:21 -04:00
|
|
|
#define _MPRINTF_REPLACE /* use our functions only */
|
|
|
|
#include <curl/mprintf.h>
|
|
|
|
|
2010-01-18 15:22:04 -05:00
|
|
|
#if defined(CURLDEBUG) && defined(CURLTOOLDEBUG)
|
|
|
|
#include "memdebug.h"
|
|
|
|
#endif
|
|
|
|
|
2004-12-14 20:38:25 -05:00
|
|
|
static const struct
|
2002-04-08 18:40:38 -04:00
|
|
|
{
|
|
|
|
const char * name;
|
|
|
|
CURLINFO id;
|
|
|
|
enum {
|
2002-04-08 18:51:21 -04:00
|
|
|
writeenv_NONE,
|
2002-04-08 18:40:38 -04:00
|
|
|
writeenv_DOUBLE,
|
|
|
|
writeenv_LONG,
|
|
|
|
writeenv_STRING
|
|
|
|
} type;
|
|
|
|
} variables[14] =
|
|
|
|
{
|
|
|
|
{"curl_url_effective", CURLINFO_EFFECTIVE_URL, writeenv_STRING},
|
2003-08-20 11:42:24 -04:00
|
|
|
{"curl_http_code", CURLINFO_RESPONSE_CODE, writeenv_LONG},
|
2002-04-08 18:40:38 -04:00
|
|
|
{"curl_time_total", CURLINFO_TOTAL_TIME, writeenv_DOUBLE},
|
|
|
|
{"curl_time_namelookup", CURLINFO_NAMELOOKUP_TIME, writeenv_DOUBLE},
|
|
|
|
{"curl_time_connect", CURLINFO_CONNECT_TIME, writeenv_DOUBLE},
|
|
|
|
{"curl_time_pretransfer", CURLINFO_PRETRANSFER_TIME, writeenv_DOUBLE},
|
|
|
|
{"curl_time_starttransfer", CURLINFO_STARTTRANSFER_TIME, writeenv_DOUBLE},
|
|
|
|
{"curl_size_header", CURLINFO_HEADER_SIZE, writeenv_LONG},
|
|
|
|
{"curl_size_request", CURLINFO_REQUEST_SIZE, writeenv_LONG},
|
|
|
|
{"curl_size_download", CURLINFO_SIZE_DOWNLOAD, writeenv_DOUBLE},
|
|
|
|
{"curl_size_upload", CURLINFO_SIZE_UPLOAD, writeenv_DOUBLE},
|
|
|
|
{"curl_speed_download", CURLINFO_SPEED_DOWNLOAD, writeenv_DOUBLE},
|
|
|
|
{"curl_speed_upload", CURLINFO_SPEED_UPLOAD, writeenv_DOUBLE},
|
2002-04-08 18:51:21 -04:00
|
|
|
{NULL, 0, writeenv_NONE}
|
2002-04-08 18:40:38 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void internalSetEnv(const char * name, char * value)
|
|
|
|
{
|
|
|
|
/* Add your OS-specific code here. */
|
|
|
|
#ifdef __riscos__
|
|
|
|
_kernel_setenv(name, value);
|
2004-03-29 07:29:25 -05:00
|
|
|
#elif defined (CURLDEBUG)
|
2010-01-18 15:22:04 -05:00
|
|
|
curl_memlog("ENV %s = %s\n", name, value);
|
2002-04-08 18:40:38 -04:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ourWriteEnv(CURL *curl)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
char *string, numtext[10];
|
|
|
|
long longinfo;
|
|
|
|
double doubleinfo;
|
2008-11-03 10:51:40 -05:00
|
|
|
|
2002-04-08 18:40:38 -04:00
|
|
|
for (i=0; variables[i].name; i++) {
|
|
|
|
switch (variables[i].type) {
|
|
|
|
case writeenv_STRING:
|
|
|
|
if (curl_easy_getinfo(curl, variables[i].id, &string) == CURLE_OK)
|
|
|
|
internalSetEnv(variables[i].name, string);
|
|
|
|
else
|
|
|
|
internalSetEnv(variables[i].name, NULL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case writeenv_LONG:
|
|
|
|
if (curl_easy_getinfo(curl, variables[i].id, &longinfo) == CURLE_OK) {
|
2008-11-03 10:51:40 -05:00
|
|
|
curl_msprintf(numtext, "%5ld", longinfo);
|
2002-04-08 18:40:38 -04:00
|
|
|
internalSetEnv(variables[i].name, numtext);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
internalSetEnv(variables[i].name, NULL);
|
|
|
|
break;
|
|
|
|
case writeenv_DOUBLE:
|
|
|
|
if (curl_easy_getinfo(curl, variables[i].id, &doubleinfo) == CURLE_OK) {
|
2008-11-03 10:51:40 -05:00
|
|
|
curl_msprintf(numtext, "%6.2f", doubleinfo);
|
2002-04-08 18:40:38 -04:00
|
|
|
internalSetEnv(variables[i].name, numtext);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
internalSetEnv(variables[i].name, NULL);
|
|
|
|
break;
|
2004-03-29 07:29:25 -05:00
|
|
|
default:
|
|
|
|
break;
|
2002-04-08 18:40:38 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2002-04-08 18:51:21 -04:00
|
|
|
|
|
|
|
#endif
|