Update of /cvsroot/monetdb/sql/src/backends/monet5/merovingian
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv1797
Modified Files:
merovingian.c monetdb.c monetdb_set.c properties.c utils.c
utils.h
Log Message:
manually propagated this commit:
date: 2009/09/04 12:04:04; author: mr-meltdown
extend confkeyval struct with expected type, such that we can check if
the input actually matches what we expect in most cases, I will
propagate this commit myself, since Current is completely different code
at the moment
U monetdb.c
Index: monetdb.c
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/monetdb.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- monetdb.c 4 Sep 2009 09:45:11 -0000 1.35
+++ monetdb.c 4 Sep 2009 12:37:16 -0000 1.36
@@ -329,14 +329,14 @@
char buf[1024];
int fd;
confkeyval ckv[] = {
- {"prefix", GDKstrdup(MONETDB5_PREFIX)},
- {"gdk_dbfarm", NULL},
- {"gdk_nr_threads", NULL},
- {"sql_logdir", NULL},
- {"mero_doproxy", GDKstrdup("yes")},
- {"mero_discoveryport", NULL},
- {"#master", GDKstrdup("no")},
- { NULL, NULL}
+ {"prefix", GDKstrdup(MONETDB5_PREFIX), STR},
+ {"gdk_dbfarm", NULL, STR},
+ {"gdk_nr_threads", NULL, INT},
+ {"sql_logdir", NULL, STR},
+ {"mero_doproxy", GDKstrdup("yes"), BOOL},
+ {"mero_discoveryport", NULL, INT},
+ {"#master", GDKstrdup("no")}, BOOL},
+ { NULL, NULL, INVALID}
};
confkeyval *kv;
#ifdef TIOCGWINSZ
@@ -426,10 +426,8 @@
/* change the keys to our names */
kv = findConfKey(ckv, "mero_doproxy");
kv->key = "forward";
- if (strcmp(kv->val, "yes") == 0 ||
- strcmp(kv->val, "true") == 0 ||
- strcmp(kv->val, "1") == 0)
- {
+ kv->type = OTHER;
+ if (strcmp(kv->val, "yes") == 0) {
GDKfree(kv->val);
kv->val = GDKstrdup("proxy");
} else {
@@ -438,6 +436,7 @@
}
kv = findConfKey(ckv, "mero_discoveryport");
kv->key = "shared";
+ kv->type = STR;
if (kv->val == NULL) {
kv->val = GDKstrdup("yes");
} else if (strcmp(kv->val, "0") == 0) {
U utils.h
Index: utils.h
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/utils.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- utils.h 1 Jul 2009 11:12:35 -0000 1.6
+++ utils.h 4 Sep 2009 12:37:16 -0000 1.7
@@ -23,15 +23,25 @@
#include <stdio.h> /* FILE* */
#include <sys/types.h> /* time_t */
+enum valtype {
+ INVALID = 0,
+ INT,
+ BOOL,
+ STR,
+ OTHER
+};
+
typedef struct _confkeyval {
char *key;
char *val;
+ enum valtype type;
} confkeyval;
char *replacePrefix(char *s, char *prefix);
void readConfFile(confkeyval *list, FILE *cnf);
void freeConfFile(confkeyval *list);
confkeyval *findConfKey(confkeyval *list, char *key);
+char *setConfVal(confkeyval *ckv, char *val);
void secondsToString(char *buf, time_t t, int longness);
void abbreviateString(char *ret, char *in, size_t width);
U merovingian.c
Index: merovingian.c
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/merovingian.c,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- merovingian.c 25 Aug 2009 12:07:31 -0000 1.56
+++ merovingian.c 4 Sep 2009 12:37:16 -0000 1.57
@@ -433,19 +433,19 @@
FILE *oerr = NULL;
pthread_mutexattr_t mta;
confkeyval ckv[] = {
- {"prefix", GDKstrdup(MONETDB5_PREFIX)},
- {"gdk_dbfarm", NULL},
- {"gdk_nr_threads", NULL},
- {"sql_logdir", NULL},
- {"mero_msglog", NULL},
- {"mero_errlog", NULL},
- {"mero_port", NULL},
- {"mero_exittimeout", NULL},
- {"mero_pidfile", NULL},
- {"mero_doproxy", NULL},
- {"mero_discoveryttl", NULL},
- {"mero_discoveryport", NULL},
- { NULL, NULL}
+ {"prefix", GDKstrdup(MONETDB5_PREFIX), STR},
+ {"gdk_dbfarm", NULL, STR},
+ {"gdk_nr_threads", NULL, INT},
+ {"sql_logdir", NULL, STR},
+ {"mero_msglog", NULL, STR},
+ {"mero_errlog", NULL, STR},
+ {"mero_port", NULL, INT},
+ {"mero_exittimeout", NULL, INT},
+ {"mero_pidfile", NULL, STR},
+ {"mero_doproxy", NULL, BOOL},
+ {"mero_discoveryttl", NULL, INT},
+ {"mero_discoveryport", NULL, INT},
+ { NULL, NULL, INVALID}
};
confkeyval *kv;
U utils.c
Index: utils.c
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/utils.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- utils.c 1 Jul 2009 11:12:35 -0000 1.9
+++ utils.c 4 Sep 2009 12:37:16 -0000 1.10
@@ -27,6 +27,7 @@
#include "utils.h"
#include <stdio.h> /* fprintf, fgets */
#include <string.h> /* memcpy */
+#include <strings.h> /* strcasecmp */
#include <gdk.h> /* GDKmalloc */
/**
@@ -66,6 +67,7 @@
char buf[1024];
confkeyval *t;
size_t len;
+ char *err;
while (fgets(buf, 1024, cnf) != NULL) {
/* eliminate fgets' newline */
@@ -73,9 +75,8 @@
for (t = list; t->key != NULL; t++) {
len = strlen(t->key);
if (*buf && strncmp(buf, t->key, len) == 0 && buf[len]
== '=') {
- if (t->val != NULL)
- GDKfree(t->val);
- t->val = GDKstrdup(buf + len + 1);
+ if ((err = setConfVal(t, buf + len + 1)) !=
NULL)
+ GDKfree(err); /* ignore, just fall back
to default */
}
}
}
@@ -110,6 +111,78 @@
}
/**
+ * Sets the value in the given confkeyval struct to val ensuring it is
+ * of the desired type. In case of type BOOL, val is converted to "yes"
+ * or "no", based on val. If the type does not match, this function
+ * returns a GDKmalloced diagnostic message, or if everything is
+ * successful, NULL. If val is NULL, this function always returns
+ * successful and unsets the value for the given key. Upon an error,
+ * the original value for the key is left untouched.
+ */
+inline char *
+setConfVal(confkeyval *ckv, char *val) {
+ /* handle the unset directly */
+ if (val == NULL) {
+ if (ckv->val != NULL) {
+ GDKfree(ckv->val);
+ ckv->val = NULL;
+ }
+ return(NULL);
+ }
+
+ /* check the input */
+ switch (ckv->type) {
+ case INVALID: {
+ char buf[256];
+ snprintf(buf, sizeof(buf),
+ "key '%s' is unitialised (invalid
value), internal error",
+ ckv->key);
+ return(GDKstrdup(buf));
+ }; break;
+ case INT: {
+ char *p = val;
+ while (*p >= '0' && *p <= '9')
+ p++;
+ if (*p != '\0') {
+ char buf[256];
+ snprintf(buf, sizeof(buf),
+ "key '%s' requires an
integer-type value, got: %s",
+ ckv->key, val);
+ return(GDKstrdup(buf));
+ }
+ }; break;
+ case BOOL: {
+ if (strcasecmp(val, "true") == 0 ||
+ strcasecmp(val, "yes") == 0 ||
+ strcmp(val, "1") == 0)
+ {
+ val = "yes";
+ } else if (strcasecmp(val, "false") == 0 ||
+ strcasecmp(val, "no") == 0 ||
+ strcmp(val, "0") == 0)
+ {
+ val = "no";
+ } else {
+ char buf[256];
+ snprintf(buf, sizeof(buf),
+ "key '%s' requires a
boolean-type value, got: %s",
+ ckv->key, val);
+ return(GDKstrdup(buf));
+ }
+ }; break;
+ case STR:
+ case OTHER:
+ /* leave as is, not much to check */
+ break;
+ }
+ if (ckv->val != NULL)
+ GDKfree(ckv->val);
+ ckv->val = GDKstrdup(val);
+
+ return(NULL);
+}
+
+/**
* Fills the array pointed to by buf with a human representation of t.
* The argument longness represents the number of units to print
* starting from the biggest unit that has a non-zero value for t.
U properties.c
Index: properties.c
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/properties.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- properties.c 4 Sep 2009 09:45:11 -0000 1.8
+++ properties.c 4 Sep 2009 12:37:16 -0000 1.9
@@ -35,11 +35,11 @@
"# This file is used by merovingian and monetdb\n"
static confkeyval _internal_prop_keys[] = {
- {"forward", NULL},
- {"shared", NULL},
- {"nthreads", NULL},
- {"master", NULL},
- { NULL, NULL}
+ {"forward", NULL, OTHER},
+ {"shared", NULL, STR},
+ {"nthreads", NULL, INT},
+ {"master", NULL, BOOL},
+ { NULL, NULL, INVALID}
};
/**
U monetdb_set.c
Index: monetdb_set.c
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/monetdb_set.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- monetdb_set.c 19 Aug 2009 13:41:08 -0000 1.1
+++ monetdb_set.c 4 Sep 2009 12:37:16 -0000 1.2
@@ -197,6 +197,7 @@
state |= 1;
}
} else {
+ char *err;
readProps(props, stats->path);
kv = findConfKey(props, property);
if (kv == NULL) {
@@ -204,12 +205,11 @@
state |= 1;
continue;
}
- if (kv->val != NULL)
- GDKfree(kv->val);
- if (type == SET) {
- kv->val = GDKstrdup(value);
- } else /* INHERIT */ {
- kv->val = NULL;
+ if ((err = setConfVal(kv, type == SET ? value : NULL))
!= NULL) {
+ fprintf(stderr, "%s: %s\n", argv[0], err);
+ GDKfree(err);
+ state |= 1;
+ continue;
}
writeProps(props, stats->path);
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins