mirror of
https://github.com/GOSTSec/sgminer
synced 2025-08-26 13:52:02 +00:00
API implement addpool command
This commit is contained in:
parent
54ef2d951b
commit
0abac0b5d9
7
README
7
README
@ -660,6 +660,13 @@ The list of requests - a (*) means it requires privileged access - and replies a
|
|||||||
stating the results of enabling pool N
|
stating the results of enabling pool N
|
||||||
The Msg includes the pool URL
|
The Msg includes the pool URL
|
||||||
|
|
||||||
|
addpool|URL,USR,PASS (*)
|
||||||
|
none There is no reply section just the STATUS section
|
||||||
|
stating the results of attempting to add pool N
|
||||||
|
The Msg includes the pool URL
|
||||||
|
Use '\\' to get a '\' and '\,' to include a comma
|
||||||
|
inside URL, USR or PASS
|
||||||
|
|
||||||
disablepool|N (*)
|
disablepool|N (*)
|
||||||
none There is no reply section just the STATUS section
|
none There is no reply section just the STATUS section
|
||||||
stating the results of disabling pool N
|
stating the results of disabling pool N
|
||||||
|
85
api.c
85
api.c
@ -264,6 +264,10 @@ static const char *JSON_PARAMETER = "parameter";
|
|||||||
#define MSG_ALRENAP 49
|
#define MSG_ALRENAP 49
|
||||||
#define MSG_ALRDISP 50
|
#define MSG_ALRDISP 50
|
||||||
#define MSG_DISLASTP 51
|
#define MSG_DISLASTP 51
|
||||||
|
#define MSG_MISPDP 52
|
||||||
|
#define MSG_INVPDP 53
|
||||||
|
#define MSG_TOOMANYP 54
|
||||||
|
#define MSG_ADDPOOL 55
|
||||||
|
|
||||||
enum code_severity {
|
enum code_severity {
|
||||||
SEVERITY_ERR,
|
SEVERITY_ERR,
|
||||||
@ -356,6 +360,10 @@ struct CODES {
|
|||||||
{ SEVERITY_INFO, MSG_ALRENAP, PARAM_POOL, "Pool %d:'%s' already enabled" },
|
{ SEVERITY_INFO, MSG_ALRENAP, PARAM_POOL, "Pool %d:'%s' already enabled" },
|
||||||
{ SEVERITY_INFO, MSG_ALRDISP, PARAM_POOL, "Pool %d:'%s' already disabled" },
|
{ SEVERITY_INFO, MSG_ALRDISP, PARAM_POOL, "Pool %d:'%s' already disabled" },
|
||||||
{ SEVERITY_ERR, MSG_DISLASTP,PARAM_POOL, "Cannot disable last active pool %d:'%s'" },
|
{ SEVERITY_ERR, MSG_DISLASTP,PARAM_POOL, "Cannot disable last active pool %d:'%s'" },
|
||||||
|
{ SEVERITY_ERR, MSG_MISPDP, PARAM_NONE, "Missing addpool details" },
|
||||||
|
{ SEVERITY_ERR, MSG_INVPDP, PARAM_STR, "Invalid addpool details '%s'" },
|
||||||
|
{ SEVERITY_ERR, MSG_TOOMANYP,PARAM_NONE, "Reached maximum number of pools (%d)" },
|
||||||
|
{ SEVERITY_SUCC, MSG_ADDPOOL, PARAM_STR, "Added pool '%s'" },
|
||||||
{ SEVERITY_FAIL, 0, 0, NULL }
|
{ SEVERITY_FAIL, 0, 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -986,6 +994,81 @@ static void switchpool(__maybe_unused SOCKETTYPE c, char *param, bool isjson)
|
|||||||
strcpy(io_buffer, message(MSG_SWITCHP, id, NULL, isjson));
|
strcpy(io_buffer, message(MSG_SWITCHP, id, NULL, isjson));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void copyadvanceafter(char ch, char **param, char **buf)
|
||||||
|
{
|
||||||
|
#define src_p (*param)
|
||||||
|
#define dst_b (*buf)
|
||||||
|
|
||||||
|
while (*src_p && *src_p != ch) {
|
||||||
|
if (*src_p == '\\' && *(src_p+1) != '\0')
|
||||||
|
src_p++;
|
||||||
|
|
||||||
|
*(dst_b++) = *(src_p++);
|
||||||
|
}
|
||||||
|
if (*src_p)
|
||||||
|
src_p++;
|
||||||
|
|
||||||
|
*(dst_b++) = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool pooldetails(char *param, char **url, char **user, char **pass)
|
||||||
|
{
|
||||||
|
char *ptr, *buf;
|
||||||
|
|
||||||
|
ptr = buf = malloc(strlen(param)+1);
|
||||||
|
if (unlikely(!buf))
|
||||||
|
quit(1, "Failed to malloc pooldetails buf");
|
||||||
|
|
||||||
|
*url = buf;
|
||||||
|
|
||||||
|
// copy url
|
||||||
|
copyadvanceafter(',', ¶m, &buf);
|
||||||
|
|
||||||
|
if (!(*param)) // missing user
|
||||||
|
goto exitsama;
|
||||||
|
|
||||||
|
*user = buf;
|
||||||
|
|
||||||
|
// copy user
|
||||||
|
copyadvanceafter(',', ¶m, &buf);
|
||||||
|
|
||||||
|
if (!*param) // missing pass
|
||||||
|
goto exitsama;
|
||||||
|
|
||||||
|
*pass = buf;
|
||||||
|
|
||||||
|
// copy pass
|
||||||
|
copyadvanceafter(',', ¶m, &buf);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
exitsama:
|
||||||
|
free(ptr);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void addpool(__maybe_unused SOCKETTYPE c, char *param, bool isjson)
|
||||||
|
{
|
||||||
|
char *url, *user, *pass;
|
||||||
|
|
||||||
|
if (param == NULL || *param == '\0') {
|
||||||
|
strcpy(io_buffer, message(MSG_MISPDP, 0, NULL, isjson));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pooldetails(param, &url, &user, &pass)) {
|
||||||
|
strcpy(io_buffer, message(MSG_INVPDP, 0, param, isjson));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (add_pool_details(true, url, user, pass) == ADD_POOL_MAXIMUM) {
|
||||||
|
strcpy(io_buffer, message(MSG_TOOMANYP, MAX_POOLS, NULL, isjson));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy(io_buffer, message(MSG_ADDPOOL, 0, url, isjson));
|
||||||
|
}
|
||||||
|
|
||||||
static void enablepool(__maybe_unused SOCKETTYPE c, char *param, bool isjson)
|
static void enablepool(__maybe_unused SOCKETTYPE c, char *param, bool isjson)
|
||||||
{
|
{
|
||||||
struct pool *pool;
|
struct pool *pool;
|
||||||
@ -1271,7 +1354,7 @@ struct CMDS {
|
|||||||
{ "gpucount", gpucount, false },
|
{ "gpucount", gpucount, false },
|
||||||
{ "cpucount", cpucount, false },
|
{ "cpucount", cpucount, false },
|
||||||
{ "switchpool", switchpool, true },
|
{ "switchpool", switchpool, true },
|
||||||
// { "addpool", addpool, true }, Not yet ...
|
{ "addpool", addpool, true },
|
||||||
{ "enablepool", enablepool, true },
|
{ "enablepool", enablepool, true },
|
||||||
{ "disablepool", disablepool, true },
|
{ "disablepool", disablepool, true },
|
||||||
{ "gpuintensity", gpuintensity, true },
|
{ "gpuintensity", gpuintensity, true },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user