Commit 71378a4bd88da80dc100e3b1ca84631b2dbfaf88

Con Kolivas 2012-06-01T22:12:08

Merge pull request #209 from kanoi/977aecc4a60928d05719e3b0b534335b1f82effa API save default config file if none specified

diff --git a/API-README b/API-README
index 706ffb0..0782457 100644
--- a/API-README
+++ b/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
                               stating success or failure saving the cgminer config
                               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"
                               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:
 
 
-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:
  'stats'
diff --git a/api.c b/api.c
index 731c4e1..b644149 100644
--- a/api.c
+++ b/api.c
@@ -161,7 +161,7 @@ static const char SEPARATOR = '|';
 #define SEPSTR "|"
 static const char GPUSEP = ',';
 
-static const char *APIVERSION = "1.10";
+static const char *APIVERSION = "1.11";
 static const char *DEAD = "Dead";
 static const char *SICK = "Sick";
 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_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_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_SUCC,  MSG_ACCOK,	PARAM_NONE,	"Privileged access OK" },
  { 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)
 {
+	char filename[PATH_MAX];
 	FILE *fcfg;
 	char *ptr;
 
 	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");
diff --git a/cgminer.c b/cgminer.c
index 9565fc1..cb4f6f2 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -3006,6 +3006,23 @@ retry:
 }
 #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
 static void set_options(void)
 {
@@ -3066,19 +3083,7 @@ retry:
 		FILE *fcfg;
 		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);
 		str = curses_input(prompt);
 		if (strcmp(str, "-1")) {
diff --git a/miner.h b/miner.h
index 4e2f752..ec9d725 100644
--- a/miner.h
+++ b/miner.h
@@ -742,6 +742,7 @@ extern void kill_work(void);
 extern void switch_pools(struct pool *selected);
 extern void remove_pool(struct pool *pool);
 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 clear_logwin(void);
 extern bool pool_tclear(struct pool *pool, bool *var);