Commit b706da9374b3e49767a1ddf8bf9dd258b565a510

Con Kolivas 2012-02-11T14:55:12

Merge branch 'reject_reason' of https://github.com/luke-jr/cgminer into reject

diff --git a/cgminer.c b/cgminer.c
index 5781391..71402f9 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -1473,12 +1473,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 563a4d7..d3b65e5 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);