Allow to load remote config files with curl
different samples of use: ccminer -c http://127.0.0.1/ccminer.json or dynamically from a web application : ccminer -c http://127.0.0.1/ccminer/config.php?h=linux Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
This commit is contained in:
parent
21f5435420
commit
629d987177
@ -225,6 +225,7 @@ features.
|
||||
>>> RELEASE HISTORY <<<
|
||||
|
||||
August 2015...
|
||||
Allow to load remote config with curl (-c http://...)
|
||||
Add Lyra2REv2 algo (Vertcoin/Zoom)
|
||||
Restore WhirlpoolX algo (VNL)
|
||||
Drop Animecoin support
|
||||
|
14
ccminer.cpp
14
ccminer.cpp
@ -2522,13 +2522,15 @@ void parse_arg(int key, char *arg)
|
||||
break;
|
||||
case 'c': {
|
||||
json_error_t err;
|
||||
if (opt_config)
|
||||
if (opt_config) {
|
||||
json_decref(opt_config);
|
||||
#if JANSSON_VERSION_HEX >= 0x020000
|
||||
opt_config = json_load_file(arg, 0, &err);
|
||||
#else
|
||||
opt_config = json_load_file(arg, &err);
|
||||
#endif
|
||||
opt_config = NULL;
|
||||
}
|
||||
if (arg && strstr(arg, "://")) {
|
||||
opt_config = json_load_url(arg, &err);
|
||||
} else {
|
||||
opt_config = JSON_LOADF(arg, &err);
|
||||
}
|
||||
if (!json_is_object(opt_config)) {
|
||||
applog(LOG_ERR, "JSON decode of %s failed", arg);
|
||||
proper_exit(EXIT_CODE_USAGE);
|
||||
|
@ -1,4 +1,4 @@
|
||||
AC_INIT([ccminer], [1.6.6-dev])
|
||||
AC_INIT([ccminer], [1.6.6])
|
||||
|
||||
AC_PREREQ([2.59c])
|
||||
AC_CANONICAL_SYSTEM
|
||||
|
4
miner.h
4
miner.h
@ -245,10 +245,14 @@ void aligned_free(void *ptr);
|
||||
|
||||
#if JANSSON_MAJOR_VERSION >= 2
|
||||
#define JSON_LOADS(str, err_ptr) json_loads((str), 0, (err_ptr))
|
||||
#define JSON_LOADF(str, err_ptr) json_load_file((str), 0, (err_ptr))
|
||||
#else
|
||||
#define JSON_LOADS(str, err_ptr) json_loads((str), (err_ptr))
|
||||
#define JSON_LOADF(str, err_ptr) json_load_file((str), (err_ptr))
|
||||
#endif
|
||||
|
||||
json_t * json_load_url(char* cfg_url, json_error_t *err);
|
||||
|
||||
#define USER_AGENT PACKAGE_NAME "/" PACKAGE_VERSION
|
||||
|
||||
void sha256_init(uint32_t *state);
|
||||
|
45
util.cpp
45
util.cpp
@ -603,6 +603,51 @@ json_t *json_rpc_longpoll(CURL *curl, char *lp_url, struct pool_infos *pool, con
|
||||
return json_rpc_call(curl, lp_url, userpass, req, false, true, keepalive, curl_err);
|
||||
}
|
||||
|
||||
json_t *json_load_url(char* cfg_url, json_error_t *err)
|
||||
{
|
||||
char err_str[CURL_ERROR_SIZE] = { 0 };
|
||||
struct data_buffer all_data = { 0 };
|
||||
int rc = 0; json_t *cfg = NULL;
|
||||
CURL *curl = curl_easy_init();
|
||||
if (unlikely(!curl)) {
|
||||
applog(LOG_ERR, "Remote config init failed!");
|
||||
return NULL;
|
||||
}
|
||||
curl_easy_setopt(curl, CURLOPT_URL, cfg_url);
|
||||
curl_easy_setopt(curl, CURLOPT_FRESH_CONNECT, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 15);
|
||||
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, err_str);
|
||||
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, all_data_cb);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &all_data);
|
||||
if (opt_proxy) {
|
||||
curl_easy_setopt(curl, CURLOPT_PROXY, opt_proxy);
|
||||
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, opt_proxy_type);
|
||||
} else if (getenv("http_proxy")) {
|
||||
if (getenv("all_proxy"))
|
||||
curl_easy_setopt(curl, CURLOPT_PROXY, getenv("all_proxy"));
|
||||
else if (getenv("ALL_PROXY"))
|
||||
curl_easy_setopt(curl, CURLOPT_PROXY, getenv("ALL_PROXY"));
|
||||
else
|
||||
curl_easy_setopt(curl, CURLOPT_PROXY, "");
|
||||
}
|
||||
rc = curl_easy_perform(curl);
|
||||
if (rc) {
|
||||
applog(LOG_ERR, "Remote config read failed: %s", err_str);
|
||||
goto err_out;
|
||||
}
|
||||
if (!all_data.buf || !all_data.len) {
|
||||
applog(LOG_ERR, "Empty data received for config");
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
cfg = JSON_LOADS((char*)all_data.buf, err);
|
||||
err_out:
|
||||
curl_easy_cleanup(curl);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlike malloc, calloc set the memory to zero
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user