Browse Source

ui+api: ask for pool name/description/algorithm when adding pool from NCurses/API.

Closes #116.

This is trivial and shouldn't be so hard: it required modifying
functions in both sgminer.c (for NCurses stuff) and api.c. There is
much code repetition, since the NCurses interface is hard-coded in.
Removing it would simplify things greatly.
refactor
Noel Maersk 11 years ago
parent
commit
3c3a58475e
  1. 30
      api.c
  2. 2
      miner.h
  3. 36
      sgminer.c

30
api.c

@ -2112,7 +2112,8 @@ static void copyadvanceafter(char ch, char **param, char **buf)
*(dst_b++) = '\0'; *(dst_b++) = '\0';
} }
static bool pooldetails(char *param, char **url, char **user, char **pass) static bool pooldetails(char *param, char **url, char **user, char **pass,
char **name, char **desc, char **algo)
{ {
char *ptr, *buf; char *ptr, *buf;
@ -2121,24 +2122,31 @@ static bool pooldetails(char *param, char **url, char **user, char **pass)
quit(1, "Failed to malloc pooldetails buf"); quit(1, "Failed to malloc pooldetails buf");
*url = buf; *url = buf;
// copy url
copyadvanceafter(',', &param, &buf); copyadvanceafter(',', &param, &buf);
if (!(*param)) // missing user if (!(*param)) // missing user
goto exitsama; goto exitsama;
*user = buf; *user = buf;
// copy user
copyadvanceafter(',', &param, &buf); copyadvanceafter(',', &param, &buf);
if (!*param) // missing pass if (!*param) // missing pass
goto exitsama; goto exitsama;
*pass = buf; *pass = buf;
copyadvanceafter(',', &param, &buf);
if (!*param) // missing name
goto exitsama;
*name = buf;
copyadvanceafter(',', &param, &buf);
if (!*param) // missing desc
goto exitsama;
*desc = buf;
copyadvanceafter(',', &param, &buf);
if (!*param) // missing algo
goto exitsama;
// copy pass *algo = buf;
copyadvanceafter(',', &param, &buf); copyadvanceafter(',', &param, &buf);
return true; return true;
@ -2151,6 +2159,7 @@ exitsama:
static void addpool(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char *param, bool isjson, __maybe_unused char group) static void addpool(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char *param, bool isjson, __maybe_unused char group)
{ {
char *url, *user, *pass; char *url, *user, *pass;
char *name, *desc, *algo;
struct pool *pool; struct pool *pool;
char *ptr; char *ptr;
@ -2159,7 +2168,8 @@ static void addpool(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char *
return; return;
} }
if (!pooldetails(param, &url, &user, &pass)) { if (!pooldetails(param, &url, &user, &pass,
&name, &desc, &algo)) {
ptr = escape_string(param, isjson); ptr = escape_string(param, isjson);
message(io_data, MSG_INVPDP, 0, ptr, isjson); message(io_data, MSG_INVPDP, 0, ptr, isjson);
if (ptr != param) if (ptr != param)
@ -2170,7 +2180,7 @@ static void addpool(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char *
pool = add_pool(); pool = add_pool();
detect_stratum(pool, url); detect_stratum(pool, url);
add_pool_details(pool, true, url, user, pass); add_pool_details(pool, true, url, user, pass, name, desc, algo);
ptr = escape_string(url, isjson); ptr = escape_string(url, isjson);
message(io_data, MSG_ADDPOOL, 0, ptr, isjson); message(io_data, MSG_ADDPOOL, 0, ptr, isjson);

2
miner.h

@ -1053,7 +1053,7 @@ extern bool detect_stratum(struct pool *pool, char *url);
extern void print_summary(void); extern void print_summary(void);
extern void adjust_quota_gcd(void); extern void adjust_quota_gcd(void);
extern struct pool *add_pool(void); extern struct pool *add_pool(void);
extern bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass); extern bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass, char *name, char *desc, char *algo);
#define MAX_GPUDEVICES 16 #define MAX_GPUDEVICES 16
#define MAX_DEVICES 4096 #define MAX_DEVICES 4096

36
sgminer.c

@ -7515,7 +7515,7 @@ static void *test_pool_thread(void *arg)
/* Always returns true that the pool details were added unless we are not /* Always returns true that the pool details were added unless we are not
* live, implying this is the only pool being added, so if no pools are * live, implying this is the only pool being added, so if no pools are
* active it returns false. */ * active it returns false. */
bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass) bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass, char *name, char *desc, char *algo)
{ {
size_t siz; size_t siz;
@ -7524,6 +7524,10 @@ bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char
pool->rpc_url = url; pool->rpc_url = url;
pool->rpc_user = user; pool->rpc_user = user;
pool->rpc_pass = pass; pool->rpc_pass = pass;
pool->name = name;
pool->description = desc;
strcpy(pool->algorithm.name, algo);
siz = strlen(pool->rpc_user) + strlen(pool->rpc_pass) + 2; siz = strlen(pool->rpc_user) + strlen(pool->rpc_pass) + 2;
pool->rpc_userpass = (char *)malloc(siz); pool->rpc_userpass = (char *)malloc(siz);
if (!pool->rpc_userpass) if (!pool->rpc_userpass)
@ -7547,23 +7551,26 @@ bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char
static bool input_pool(bool live) static bool input_pool(bool live)
{ {
char *url = NULL, *user = NULL, *pass = NULL; char *url = NULL, *user = NULL, *pass = NULL;
char *name = NULL, *desc = NULL, *algo = NULL;
struct pool *pool; struct pool *pool;
bool ret = false; bool ret = false;
immedok(logwin, true); immedok(logwin, true);
wlogprint("Input server details.\n"); wlogprint("Input server details.\n");
/* Get user input */
url = curses_input("URL"); url = curses_input("URL");
if (!url) if (!url) goto out;
goto out; user = curses_input("User name");
if (!user) goto out;
user = curses_input("Username");
if (!user)
goto out;
pass = curses_input("Password"); pass = curses_input("Password");
if (!pass) if (!pass) goto out;
goto out; name = curses_input("Pool name (optional)");
if (strcmp(name, "-1") == 0) strcpy(name, "");
desc = curses_input("Description (optional)");
if (strcmp(desc, "-1") == 0) strcpy(desc, "");
algo = curses_input("Algorithm (optional)");
if (strcmp(name, "-1") == 0) strcpy(algo, "");
pool = add_pool(); pool = add_pool();
@ -7580,7 +7587,8 @@ static bool input_pool(bool live)
url = httpinput; url = httpinput;
} }
ret = add_pool_details(pool, live, url, user, pass); ret = add_pool_details(pool, live, url, user, pass,
name, desc, algo);
out: out:
immedok(logwin, false); immedok(logwin, false);
@ -7591,6 +7599,12 @@ out:
free(user); free(user);
if (pass) if (pass)
free(pass); free(pass);
if (name)
free(name);
if (desc)
free(desc);
if (algo)
free(algo);
} }
return ret; return ret;
} }

Loading…
Cancel
Save