Browse Source

Move absolute_uri function to util.c

Luke Dashjr 13 years ago
parent
commit
de57206012
3 changed files with 26 additions and 24 deletions
  1. 0 24
      miner.c
  2. 24 0
      util.c
  3. 2 0
      util.h

+ 0 - 24
miner.c

@@ -5991,30 +5991,6 @@ static bool stratum_works(struct pool *pool)
 	return true;
 	return true;
 }
 }
 
 
-// NOTE: This assumes reference URI is a root
-static char *absolute_uri(char *uri, const char *ref)
-{
-	if (strstr(uri, "://"))
-		return strdup(uri);
-
-	char *copy_start, *abs;
-	bool need_slash = false;
-
-	copy_start = (uri[0] == '/') ? &uri[1] : uri;
-	if (ref[strlen(ref) - 1] != '/')
-		need_slash = true;
-
-	abs = malloc(strlen(ref) + strlen(copy_start) + 2);
-	if (!abs) {
-		applog(LOG_ERR, "Malloc failure in absolute_uri");
-		return NULL;
-	}
-
-	sprintf(abs, "%s%s%s", ref, need_slash ? "/" : "", copy_start);
-
-	return abs;
-}
-
 static bool pool_active(struct pool *pool, bool pinging)
 static bool pool_active(struct pool *pool, bool pinging)
 {
 {
 	struct timeval tv_getwork, tv_getwork_reply;
 	struct timeval tv_getwork, tv_getwork_reply;

+ 24 - 0
util.c

@@ -622,6 +622,30 @@ bool our_curl_supports_proxy_uris()
 	return data->age && data->version_num >= (( 7 <<16)|( 21 <<8)| 7);  // 7.21.7
 	return data->age && data->version_num >= (( 7 <<16)|( 21 <<8)| 7);  // 7.21.7
 }
 }
 
 
+// NOTE: This assumes reference URI is a root
+char *absolute_uri(char *uri, const char *ref)
+{
+	if (strstr(uri, "://"))
+		return strdup(uri);
+
+	char *copy_start, *abs;
+	bool need_slash = false;
+
+	copy_start = (uri[0] == '/') ? &uri[1] : uri;
+	if (ref[strlen(ref) - 1] != '/')
+		need_slash = true;
+
+	abs = malloc(strlen(ref) + strlen(copy_start) + 2);
+	if (!abs) {
+		applog(LOG_ERR, "Malloc failure in absolute_uri");
+		return NULL;
+	}
+
+	sprintf(abs, "%s%s%s", ref, need_slash ? "/" : "", copy_start);
+
+	return abs;
+}
+
 /* Returns a malloced array string of a binary value of arbitrary length. The
 /* Returns a malloced array string of a binary value of arbitrary length. The
  * array is rounded up to a 4 byte size to appease architectures that need
  * array is rounded up to a 4 byte size to appease architectures that need
  * aligned array  sizes */
  * aligned array  sizes */

+ 2 - 0
util.h

@@ -54,6 +54,8 @@ struct cgpu_info;
 extern void json_rpc_call_async(CURL *, const char *url, const char *userpass, const char *rpc_req, bool longpoll, struct pool *pool, bool share, void *priv);
 extern void json_rpc_call_async(CURL *, const char *url, const char *userpass, const char *rpc_req, bool longpoll, struct pool *pool, bool share, void *priv);
 extern json_t *json_rpc_call_completed(CURL *, int rc, bool probe, int *rolltime, void *out_priv);
 extern json_t *json_rpc_call_completed(CURL *, int rc, bool probe, int *rolltime, void *out_priv);
 
 
+extern char *absolute_uri(char *uri, const char *ref);  // ref must be a root URI
+
 extern void gen_hash(unsigned char *data, unsigned char *hash, int len);
 extern void gen_hash(unsigned char *data, unsigned char *hash, int len);
 extern void hash_data(unsigned char *out_hash, const unsigned char *data);
 extern void hash_data(unsigned char *out_hash, const unsigned char *data);
 extern void real_block_target(unsigned char *target, const unsigned char *data);
 extern void real_block_target(unsigned char *target, const unsigned char *data);