Browse Source

Merge pull request #209 from kanoi/977aecc4a60928d05719e3b0b534335b1f82effa

API save default config file if none specified
Con Kolivas 14 years ago
parent
commit
71378a4bd8
4 changed files with 37 additions and 18 deletions
  1. 13 1
      API-README
  2. 5 4
      api.c
  3. 18 13
      cgminer.c
  4. 1 0
      miner.h

+ 13 - 1
API-README

@@ -200,6 +200,8 @@ The list of requests - a (*) means it requires privileged access - and replies a
                none           There is no reply section just the STATUS section
                none           There is no reply section just the STATUS section
                               stating success or failure saving the cgminer config
                               stating success or failure saving the cgminer config
                               to filename
                               to filename
+                              The filename is optional and will use the cgminer
+                              default if not specified
 
 
  quit (*)      none           There is no status section but just a single "BYE"
  quit (*)      none           There is no status section but just a single "BYE"
                               reply before cgminer quits
                               reply before cgminer quits
@@ -283,7 +285,17 @@ miner.php - an example web page to access the API
 Feature Changelog for external applications using the API:
 Feature Changelog for external applications using the API:
 
 
 
 
-API V1.10
+API V1.11
+
+Modified API commands:
+ 'save' no longer requires a filename (use default if not specified)
+
+'save' incorrectly returned status E (error) on success before.
+It now correctly returns S (success)
+
+----------
+
+API V1.10 (cgminer v2.4.1)
 
 
 Added API commands:
 Added API commands:
  'stats'
  'stats'

+ 5 - 4
api.c

@@ -161,7 +161,7 @@ static const char SEPARATOR = '|';
 #define SEPSTR "|"
 #define SEPSTR "|"
 static const char GPUSEP = ',';
 static const char GPUSEP = ',';
 
 
-static const char *APIVERSION = "1.10";
+static const char *APIVERSION = "1.11";
 static const char *DEAD = "Dead";
 static const char *DEAD = "Dead";
 static const char *SICK = "Sick";
 static const char *SICK = "Sick";
 static const char *NOSTART = "NoStart";
 static const char *NOSTART = "NoStart";
@@ -465,7 +465,7 @@ struct CODES {
  { SEVERITY_SUCC,  MSG_GPUFAN,	PARAM_BOTH,	"Setting GPU %d fan to (%s) reported succeess" },
  { SEVERITY_SUCC,  MSG_GPUFAN,	PARAM_BOTH,	"Setting GPU %d fan to (%s) reported succeess" },
  { SEVERITY_ERR,   MSG_MISFN,	PARAM_NONE,	"Missing save filename parameter" },
  { SEVERITY_ERR,   MSG_MISFN,	PARAM_NONE,	"Missing save filename parameter" },
  { SEVERITY_ERR,   MSG_BADFN,	PARAM_STR,	"Can't open or create save file '%s'" },
  { SEVERITY_ERR,   MSG_BADFN,	PARAM_STR,	"Can't open or create save file '%s'" },
- { SEVERITY_ERR,   MSG_SAVED,	PARAM_STR,	"Configuration saved to file '%s'" },
+ { SEVERITY_SUCC,  MSG_SAVED,	PARAM_STR,	"Configuration saved to file '%s'" },
  { SEVERITY_ERR,   MSG_ACCDENY,	PARAM_STR,	"Access denied to '%s' command" },
  { SEVERITY_ERR,   MSG_ACCDENY,	PARAM_STR,	"Access denied to '%s' command" },
  { SEVERITY_SUCC,  MSG_ACCOK,	PARAM_NONE,	"Privileged access OK" },
  { SEVERITY_SUCC,  MSG_ACCOK,	PARAM_NONE,	"Privileged access OK" },
  { SEVERITY_SUCC,  MSG_ENAPOOL,	PARAM_POOL,	"Enabling pool %d:'%s'" },
  { SEVERITY_SUCC,  MSG_ENAPOOL,	PARAM_POOL,	"Enabling pool %d:'%s'" },
@@ -1979,12 +1979,13 @@ static void devdetails(__maybe_unused SOCKETTYPE c, __maybe_unused char *param,
 
 
 void dosave(__maybe_unused SOCKETTYPE c, char *param, bool isjson)
 void dosave(__maybe_unused SOCKETTYPE c, char *param, bool isjson)
 {
 {
+	char filename[PATH_MAX];
 	FILE *fcfg;
 	FILE *fcfg;
 	char *ptr;
 	char *ptr;
 
 
 	if (param == NULL || *param == '\0') {
 	if (param == NULL || *param == '\0') {
-		strcpy(io_buffer, message(MSG_MISFN, 0, NULL, isjson));
-		return;
+		default_save_file(filename);
+		param = filename;
 	}
 	}
 
 
 	fcfg = fopen(param, "w");
 	fcfg = fopen(param, "w");

+ 18 - 13
cgminer.c

@@ -3006,6 +3006,23 @@ retry:
 }
 }
 #endif
 #endif
 
 
+void default_save_file(char *filename)
+{
+#if defined(unix)
+	if (getenv("HOME") && *getenv("HOME")) {
+	        strcpy(filename, getenv("HOME"));
+		strcat(filename, "/");
+	}
+	else
+		strcpy(filename, "");
+	strcat(filename, ".cgminer/");
+	mkdir(filename, 0777);
+#else
+	strcpy(filename, "");
+#endif
+	strcat(filename, def_conf);
+}
+
 #ifdef HAVE_CURSES
 #ifdef HAVE_CURSES
 static void set_options(void)
 static void set_options(void)
 {
 {
@@ -3066,19 +3083,7 @@ retry:
 		FILE *fcfg;
 		FILE *fcfg;
 		char *str, filename[PATH_MAX], prompt[PATH_MAX + 50];
 		char *str, filename[PATH_MAX], prompt[PATH_MAX + 50];
 
 
-#if defined(unix)
-		if (getenv("HOME") && *getenv("HOME")) {
-		        strcpy(filename, getenv("HOME"));
-			strcat(filename, "/");
-		}
-		else
-			strcpy(filename, "");
-		strcat(filename, ".cgminer/");
-		mkdir(filename, 0777);
-#else
-		strcpy(filename, "");
-#endif
-		strcat(filename, def_conf);
+		default_save_file(filename);
 		sprintf(prompt, "Config filename to write (Enter for default) [%s]", filename);
 		sprintf(prompt, "Config filename to write (Enter for default) [%s]", filename);
 		str = curses_input(prompt);
 		str = curses_input(prompt);
 		if (strcmp(str, "-1")) {
 		if (strcmp(str, "-1")) {

+ 1 - 0
miner.h

@@ -742,6 +742,7 @@ extern void kill_work(void);
 extern void switch_pools(struct pool *selected);
 extern void switch_pools(struct pool *selected);
 extern void remove_pool(struct pool *pool);
 extern void remove_pool(struct pool *pool);
 extern void write_config(FILE *fcfg);
 extern void write_config(FILE *fcfg);
+extern void default_save_file(char *filename);
 extern void log_curses(int prio, const char *f, va_list ap);
 extern void log_curses(int prio, const char *f, va_list ap);
 extern void clear_logwin(void);
 extern void clear_logwin(void);
 extern bool pool_tclear(struct pool *pool, bool *var);
 extern bool pool_tclear(struct pool *pool, bool *var);