Allow the user/pass userpass urls to be input in any order.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
diff --git a/main.c b/main.c
index a2674a9..7e91836 100644
--- a/main.c
+++ b/main.c
@@ -184,6 +184,7 @@ static struct pool *pools = NULL;
static struct pool *currentpool;
static int pool_no;
static int total_pools;
+static int total_urls, total_users, total_passes, total_userpasses;
static bool curses_active = false;
@@ -349,8 +350,10 @@ static char *set_url(const char *arg, char **p)
{
struct pool *pool;
- add_pool();
- pool = &pools[total_pools - 1];
+ total_urls++;
+ if (total_urls > total_pools)
+ add_pool();
+ pool = &pools[total_urls - 1];
opt_set_charp(arg, &pool->rpc_url);
if (strncmp(arg, "http://", 7) &&
@@ -364,10 +367,13 @@ static char *set_user(const char *arg, char **p)
{
struct pool *pool;
- if (!total_pools)
- return "No URL set for user";
+ if (total_userpasses)
+ return "Use only user + pass or userpass, but not both";
+ total_users++;
+ if (total_users > total_pools)
+ add_pool();
- pool = &pools[total_pools - 1];
+ pool = &pools[total_users - 1];
opt_set_charp(arg, &pool->rpc_user);
return NULL;
@@ -377,10 +383,13 @@ static char *set_pass(const char *arg, char **p)
{
struct pool *pool;
- if (!total_pools)
- return "No URL set for pass";
+ if (total_userpasses)
+ return "Use only user + pass or userpass, but not both";
+ total_passes++;
+ if (total_passes > total_pools)
+ add_pool();
- pool = &pools[total_pools - 1];
+ pool = &pools[total_passes - 1];
opt_set_charp(arg, &pool->rpc_pass);
return NULL;
@@ -390,10 +399,13 @@ static char *set_userpass(const char *arg, char **p)
{
struct pool *pool;
- if (!total_pools)
- return "No URL set for userpass";
+ if (total_users || total_passes)
+ return "Use only user + pass or userpass, but not both";
+ total_userpasses++;
+ if (total_userpasses > total_pools)
+ add_pool();
- pool = &pools[total_pools - 1];
+ pool = &pools[total_userpasses - 1];
opt_set_charp(arg, &pool->rpc_userpass);
return NULL;