Commit f7a9897e1300fff4b21a8465f0d65ee211d62f18

Luke Dashjr 2012-01-26T00:07:42

Display X-Reject-Reason, when provided

diff --git a/cgminer.c b/cgminer.c
index cd79a19..88832ab 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -1418,12 +1418,30 @@ static bool submit_upstream_work(const struct work *work)
 		if (opt_debug)
 			applog(LOG_DEBUG, "PROOF OF WORK RESULT: false (booooo)");
 		if (!QUIET) {
+			char wherebuf[17];
+			char *where = wherebuf;
+			char reasonbuf[32];
+			char *reason = reasonbuf;
+
 			if (total_pools > 1)
-				applog(LOG_NOTICE, "Rejected %s %s %d thread %d pool %d",
-				       hashshow, cgpu->api->name, cgpu->device_id, thr_id, work->pool->pool_no);
+				sprintf(where, " pool %d", work->pool->pool_no);
 			else
-				applog(LOG_NOTICE, "Rejected %s %s %d thread %d",
-				       hashshow, cgpu->api->name, cgpu->device_id, thr_id);
+				where = "";
+			
+			res = json_object_get(val, "reject-reason");
+			if (res) {
+				const char *reasontmp = json_string_value(res);
+				size_t reasonLen = strlen(reasontmp);
+				if (reasonLen > 28)
+					reasonLen = 28;
+				reason[0] = ' '; reason[1] = '(';
+				memcpy(2 + reason, reasontmp, reasonLen);
+				reason[reasonLen + 2] = ')'; reason[reasonLen + 3] = '\0';
+			} else
+				reason = "";
+			
+			applog(LOG_NOTICE, "Rejected %s %s %d thread %d%s%s",
+			       hashshow, cgpu->api->name, cgpu->device_id, thr_id, where, reason);
 		}
 	}
 
diff --git a/util.c b/util.c
index 9a8f08e..0e9f745 100644
--- a/util.c
+++ b/util.c
@@ -57,6 +57,7 @@ struct upload_buffer {
 struct header_info {
 	char		*lp_path;
 	bool		has_rolltime;
+	char		*reason;
 };
 
 struct tq_ent {
@@ -232,6 +233,11 @@ static size_t resp_hdr_cb(void *ptr, size_t size, size_t nmemb, void *user_data)
 		val = NULL;
 	}
 
+	if (!strcasecmp("X-Reject-Reason", key)) {
+		hi->reason = val;	/* steal memory reference */
+		val = NULL;
+	}
+
 out:
 	free(key);
 	free(val);
@@ -465,6 +471,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));
+
 	successful_connect = true;
 	databuf_free(&all_data);
 	curl_slist_free_all(headers);