From 8d7a8704798bb2b09e0caf3cfb30b9d9755dcf5f Mon Sep 17 00:00:00 2001 From: pooler Date: Wed, 13 Jun 2012 01:08:20 +0200 Subject: [PATCH] Add support for the X-Reject-Reason extension --- cpu-miner.c | 8 ++++++++ util.c | 20 ++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/cpu-miner.c b/cpu-miner.c index 93e871d..e813aaf 100644 --- a/cpu-miner.c +++ b/cpu-miner.c @@ -323,6 +323,14 @@ static bool submit_upstream_work(CURL *curl, struct work *work) s, json_is_true(res) ? "(yay!!!)" : "(booooo)"); + if (opt_debug) { + json_t *tmp; + const char *reason; + tmp = json_object_get(val, "reject-reason"); + if (tmp && (reason = json_string_value(tmp))) + applog(LOG_DEBUG, "DEBUG: reject reason: %s", reason); + } + json_decref(val); rc = true; diff --git a/util.c b/util.c index adefef5..b671da4 100644 --- a/util.c +++ b/util.c @@ -46,6 +46,7 @@ struct upload_buffer { struct header_info { char *lp_path; + char *reason; }; struct tq_ent { @@ -224,14 +225,16 @@ static size_t resp_hdr_cb(void *ptr, size_t size, size_t nmemb, void *user_data) if (!*val) /* skip blank value */ goto out; - if (opt_protocol) - applog(LOG_DEBUG, "HTTP hdr(%s): %s", key, val); - if (!strcasecmp("X-Long-Polling", key)) { hi->lp_path = val; /* steal memory reference */ val = NULL; } + if (!strcasecmp("X-Reject-Reason", key)) { + hi->reason = val; /* steal memory reference */ + val = NULL; + } + out: free(key); free(val); @@ -318,10 +321,8 @@ json_t *json_rpc_call(CURL *curl, const char *url, curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_err_str); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout); - if (lp_scanning) { - curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, resp_hdr_cb); - curl_easy_setopt(curl, CURLOPT_HEADERDATA, &hi); - } + curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, resp_hdr_cb); + curl_easy_setopt(curl, CURLOPT_HEADERDATA, &hi); if (opt_proxy) { curl_easy_setopt(curl, CURLOPT_PROXY, opt_proxy); curl_easy_setopt(curl, CURLOPT_PROXYTYPE, opt_proxy_type); @@ -366,7 +367,7 @@ json_t *json_rpc_call(CURL *curl, const char *url, } /* If X-Long-Polling was found, activate long polling */ - if (hi.lp_path) { + if (lp_scanning && hi.lp_path) { have_longpoll = true; tq_push(thr_info[longpoll_thr_id].q, hi.lp_path); } else @@ -415,6 +416,9 @@ json_t *json_rpc_call(CURL *curl, const char *url, goto err_out; } + if (hi.reason) + json_object_set_new(val, "reject-reason", json_string(hi.reason)); + databuf_free(&all_data); curl_slist_free_all(headers); curl_easy_reset(curl);