/*
- * $Id: cache_cf.cc,v 1.408 2002/06/23 14:50:06 hno Exp $
+ * $Id: cache_cf.cc,v 1.409 2002/07/06 12:37:40 hno Exp $
*
* DEBUG: section 3 Configuration File Parsing
* AUTHOR: Harvest Derived
return 0;
}
-
/*
- * Use this #define in all the parse*() functions. Assumes char *token is
- * defined
+ * These functions is the same as atoi/l/f, except that they check for errors
*/
+static long
+xatol(const char *token)
+{
+ char *end;
+ long ret = strtol(token, &end, 10);
+ if (ret == 0 && end == token)
+ self_destruct();
+ return ret;
+}
+
+static int
+xatoi(const char *token)
+{
+ return xatol(token);
+}
+
+static double
+xatof(const char *token)
+{
+ char *end;
+ double ret = strtod(token, &end);
+ if (ret == 0 && end == token)
+ self_destruct();
+ return ret;
+}
+
int
GetInteger(void)
{
self_destruct();
if ((token = strtok(NULL, w_space)) == NULL)
self_destruct();
- d = atof(token);
+ d = xatof(token);
m = u; /* default to 'units' if none specified */
if (0 == d)
(void) 0;
self_destruct();
if ((token = strtok(NULL, w_space)) == NULL)
self_destruct();
- d = atof(token);
+ d = xatof(token);
m = u; /* default to 'units' if none specified */
if (0.0 == d)
(void) 0;
{
int read_only = 0;
if (value)
- read_only = atoi(value);
+ read_only = xatoi(value);
else
read_only = 1;
sd->flags.read_only = read_only;
if (!value)
self_destruct();
- size = atoi(value);
+ size = xatoi(value);
if (reconfiguring && sd->max_objsize != size)
debug(3, 1) ("Cache dir '%s' max object size now %ld\n", sd->path, (long int) size);
} else if (!strcasecmp(token, "multicast-responder")) {
p->options.mcast_responder = 1;
} else if (!strncasecmp(token, "weight=", 7)) {
- p->weight = atoi(token + 7);
+ p->weight = xatoi(token + 7);
} else if (!strncasecmp(token, "basetime=", 9)) {
- p->basetime = atoi(token + 9);
+ p->basetime = xatoi(token + 9);
} else if (!strcasecmp(token, "closest-only")) {
p->options.closest_only = 1;
} else if (!strncasecmp(token, "ttl=", 4)) {
- p->mcast.ttl = atoi(token + 4);
+ p->mcast.ttl = xatoi(token + 4);
if (p->mcast.ttl < 0)
p->mcast.ttl = 0;
if (p->mcast.ttl > 128)
p->login = xstrdup(token + 6);
rfc1738_unescape(p->login);
} else if (!strncasecmp(token, "connect-timeout=", 16)) {
- p->connect_timeout = atoi(token + 16);
+ p->connect_timeout = xatoi(token + 16);
#if USE_CACHE_DIGESTS
} else if (!strncasecmp(token, "digest-url=", 11)) {
p->digest_url = xstrdup(token + 11);
} else if (!strcasecmp(token, "allow-miss")) {
p->options.allow_miss = 1;
} else if (!strncasecmp(token, "max-conn=", 9)) {
- p->max_conn = atoi(token + 9);
+ p->max_conn = xatoi(token + 9);
} else {
debug(3, 0) ("parse_peer: token='%s'\n", token);
self_destruct();
/* host:port */
host = token;
*t = '\0';
- port = (unsigned short) atoi(t + 1);
+ port = (unsigned short) xatoi(t + 1);
if (0 == port)
self_destruct();
- } else if ((port = atoi(token)) > 0) {
+ } else if ((port = xatoi(token)) > 0) {
/* port */
} else {
self_destruct();
/* host:port */
host = token;
*t = '\0';
- port = (unsigned short) atoi(t + 1);
+ port = (unsigned short) xatoi(t + 1);
if (0 == port)
self_destruct();
- } else if ((port = atoi(token)) > 0) {
+ } else if ((port = xatoi(token)) > 0) {
/* port */
} else {
self_destruct();
safe_free(s->key);
s->key = xstrdup(token + 4);
} else if (strncmp(token, "version=", 8) == 0) {
- s->version = atoi(token + 8);
+ s->version = xatoi(token + 8);
} else if (strncmp(token, "options=", 8) == 0) {
safe_free(s->options);
s->options = xstrdup(token + 8);