summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2004-07-22 07:51:02 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2004-07-22 07:51:02 +0000
commite93aa4b09ce05117d08d52487f72417413edfbb1 (patch)
treee7bf2269da17c6f04373befe0e71e0cdcd6fcd5e
parent1f019981e437ff4c92c183d9bcbb3907915ab3ff (diff)
Now keeps integers within range, and saves a version number in the cfg file, refusing to load too old versions
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4916 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/lib/configfile.c24
-rw-r--r--apps/plugins/lib/configfile.h6
2 files changed, 25 insertions, 5 deletions
diff --git a/apps/plugins/lib/configfile.c b/apps/plugins/lib/configfile.c
index ffa325038c..ff4809a3f4 100644
--- a/apps/plugins/lib/configfile.c
+++ b/apps/plugins/lib/configfile.c
@@ -26,7 +26,8 @@ void configfile_init(struct plugin_api* newrb)
cfg_rb = newrb;
}
-int configfile_save(char *filename, struct configdata *cfg, int num_items)
+int configfile_save(const char *filename, struct configdata *cfg,
+ int num_items, int version)
{
int fd;
int i;
@@ -37,6 +38,8 @@ int configfile_save(char *filename, struct configdata *cfg, int num_items)
if(fd < 0)
return fd*10 - 1;
+ cfg_rb->fprintf(fd, "file version: %d\n", version);
+
for(i = 0;i < num_items;i++) {
switch(cfg[i].type) {
case TYPE_INT:
@@ -64,13 +67,16 @@ int configfile_save(char *filename, struct configdata *cfg, int num_items)
return 0;
}
-int configfile_load(char *filename, struct configdata *cfg, int num_items)
+int configfile_load(const char *filename, struct configdata *cfg,
+ int num_items, int min_version)
{
int fd;
int i, j;
char *name;
char *val;
char buf[MAX_PATH];
+ int file_version = -1;
+ int tmp;
cfg_rb->snprintf(buf, MAX_PATH, "/.rockbox/rocks/%s", filename);
fd = cfg_rb->open(buf, O_RDONLY);
@@ -79,12 +85,24 @@ int configfile_load(char *filename, struct configdata *cfg, int num_items)
while(cfg_rb->read_line(fd, buf, MAX_PATH) > 0) {
cfg_rb->settings_parseline(buf, &name, &val);
+
+ /* Bail out if the file version is too old */
+ if(!cfg_rb->strcmp("file version", name)) {
+ file_version = cfg_rb->atoi(val);
+ if(file_version < min_version) {
+ cfg_rb->close(fd);
+ return -1;
+ }
+ }
for(i = 0;i < num_items;i++) {
if(!cfg_rb->strcmp(cfg[i].name, name)) {
switch(cfg[i].type) {
case TYPE_INT:
- *cfg[i].val = cfg_rb->atoi(val);
+ tmp = cfg_rb->atoi(val);
+ /* Only set it if it's within range */
+ if(tmp >= cfg[i].min && tmp <= cfg[i].max)
+ *cfg[i].val = tmp;
break;
case TYPE_ENUM:
diff --git a/apps/plugins/lib/configfile.h b/apps/plugins/lib/configfile.h
index 78cc8b1b6c..fcce7de275 100644
--- a/apps/plugins/lib/configfile.h
+++ b/apps/plugins/lib/configfile.h
@@ -38,7 +38,9 @@ struct configdata
};
void configfile_init(struct plugin_api* newrb);
-int configfile_save(char *filename, struct configdata *cfg, int num_items);
-int configfile_load(char *filename, struct configdata *cfg, int num_items);
+int configfile_save(const char *filename, struct configdata *cfg,
+ int num_items, int version);
+int configfile_load(const char *filename, struct configdata *cfg,
+ int num_items, int min_version);
#endif