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

2
miner.h

@ -1053,7 +1053,7 @@ extern bool detect_stratum(struct pool *pool, char *url); @@ -1053,7 +1053,7 @@ extern bool detect_stratum(struct pool *pool, char *url);
extern void print_summary(void);
extern void adjust_quota_gcd(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_DEVICES 4096

36
sgminer.c

@ -7515,7 +7515,7 @@ static void *test_pool_thread(void *arg) @@ -7515,7 +7515,7 @@ static void *test_pool_thread(void *arg)
/* 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
* 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;
@ -7524,6 +7524,10 @@ bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char @@ -7524,6 +7524,10 @@ bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char
pool->rpc_url = url;
pool->rpc_user = user;
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;
pool->rpc_userpass = (char *)malloc(siz);
if (!pool->rpc_userpass)
@ -7547,23 +7551,26 @@ bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char @@ -7547,23 +7551,26 @@ bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char
static bool input_pool(bool live)
{
char *url = NULL, *user = NULL, *pass = NULL;
char *name = NULL, *desc = NULL, *algo = NULL;
struct pool *pool;
bool ret = false;
immedok(logwin, true);
wlogprint("Input server details.\n");
/* Get user input */
url = curses_input("URL");
if (!url)
goto out;
user = curses_input("Username");
if (!user)
goto out;
if (!url) goto out;
user = curses_input("User name");
if (!user) goto out;
pass = curses_input("Password");
if (!pass)
goto out;
if (!pass) 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();
@ -7580,7 +7587,8 @@ static bool input_pool(bool live) @@ -7580,7 +7587,8 @@ static bool input_pool(bool live)
url = httpinput;
}
ret = add_pool_details(pool, live, url, user, pass);
ret = add_pool_details(pool, live, url, user, pass,
name, desc, algo);
out:
immedok(logwin, false);
@ -7591,6 +7599,12 @@ out: @@ -7591,6 +7599,12 @@ out:
free(user);
if (pass)
free(pass);
if (name)
free(name);
if (desc)
free(desc);
if (algo)
free(algo);
}
return ret;
}

Loading…
Cancel
Save