/*
- * $Id: ACLIntRange.cc,v 1.8 2006/08/26 11:38:56 serassio Exp $
+ * $Id: ACLIntRange.cc,v 1.9 2006/10/08 13:10:34 serassio Exp $
*
* DEBUG: section 28 Access Control
* AUTHOR: Robert Collins
#include "squid.h"
#include "ACLIntRange.h"
#include "wordlist.h"
+#include "Parsing.h"
/* explicit instantiation required for some systems */
void
ACLIntRange::parse()
{
- char *t = NULL;
+ char *a;
- while ((t = strtokFile())) {
- int port = atoi(t);
+ while ((a = strtokFile())) {
+ char *b = strchr(a, '-');
+ unsigned short port1, port2;
- if (port > 0 && port < 65536) {
- RangeType temp (0,0);
- temp.start = port;
- t = strchr(t, '-');
+ if (b)
+ *b++ = '\0';
- if (t && *(++t)) {
- port = atoi(t);
+ port1 = xatos(a);
- if (port > 0 && port < 65536 && port > temp.start) {
- temp.end = port+1;
- } else {
- debug(28, 0) ("ACLIntRange::parse: Invalid port range\n");
- self_destruct();
- }
- } else
- temp.end = temp.start+1;
+ if (b)
+ port2 = xatos(b);
+ else
+ port2 = port1;
+ if (port2 >= port1) {
+ RangeType temp (0,0);
+ temp.start = port1;
+ temp.end = port2+1;
ranges.push_back(temp);
} else {
debug(28, 0) ("ACLIntRange::parse: Invalid port value\n");
/*
- * $Id: ACLMaxUserIP.cc,v 1.10 2006/04/23 11:10:31 robertc Exp $
+ * $Id: ACLMaxUserIP.cc,v 1.11 2006/10/08 13:10:34 serassio Exp $
*
* DEBUG: section 28 Access Control
* AUTHOR: Duane Wessels
if (!t)
return;
- maximum = atoi(t);
+ maximum = xatoi(t);
debug(28, 5) ("aclParseUserMaxIP: Max IP address's %d\n", (int) maximum);
/*
- * $Id: Parsing.cc,v 1.2 2005/11/21 23:06:51 wessels Exp $
+ * $Id: Parsing.cc,v 1.3 2006/10/08 13:10:34 serassio Exp $
*
* DEBUG: section 3 Configuration File Parsing
* AUTHOR: Harvest Derived
* These functions is the same as atoi/l/f, except that they check for errors
*/
-long
-xatol(const char *token)
+double
+xatof(const char *token)
{
char *end;
- long ret = strtol(token, &end, 10);
+ double ret = strtod(token, &end);
if (ret == 0 && end == token)
self_destruct();
return xatol(token);
}
+long
+xatol(const char *token)
+{
+ char *end;
+ long ret = strtol(token, &end, 10);
+
+ if (end == token || *end)
+ self_destruct();
+
+ return ret;
+}
+
+unsigned short
+xatos(const char *token)
+{
+ long port = xatol(token);
+
+ if (port & ~0xFFFF)
+ self_destruct();
+
+ return port;
+}
+
int
GetInteger(void)
{
return i;
}
+u_short
+GetShort(void)
+{
+ char *token = strtok(NULL, w_space);
+
+ if (token == NULL)
+ self_destruct();
+
+ return xatos(token);
+}
+
bool
StringToInt(const char *s, int &result, const char **p, int base)
{
/*
- * $Id: Parsing.h,v 1.2 2005/11/21 23:06:51 wessels Exp $
+ * $Id: Parsing.h,v 1.3 2006/10/08 13:10:34 serassio Exp $
*
* DEBUG: section 3 Configuration File Parsing
* AUTHOR: Harvest Derived
#include "squid.h"
-extern long xatol(const char *token);
+extern double xatof(const char *token);
extern int xatoi(const char *token);
+extern long xatol(const char *token);
+extern unsigned short xatos(const char *token);
extern int GetInteger(void);
+extern u_short GetShort(void);
// on success, returns true and sets *p (if any) to the end of the integer
extern bool StringToInt(const char *str, int &result, const char **p, int base);
/*
- * $Id: cache_cf.cc,v 1.500 2006/07/02 16:53:46 serassio Exp $
+ * $Id: cache_cf.cc,v 1.501 2006/10/08 13:10:34 serassio Exp $
*
* DEBUG: section 3 Configuration File Parsing
* AUTHOR: Harvest Derived
LegacyParser.destruct();
}
-/*
- * These functions is the same as atoi/l/f, except that they check for errors
- */
-
-static double
-xatof(const char *token)
-{
- char *end;
- double ret = strtod(token, &end);
-
- if (ret == 0 && end == token)
- self_destruct();
-
- return ret;
-}
-
static void
update_maxobjsize(void)
{
{
char *token = NULL;
peer *p;
- int i;
CBDATA_INIT_TYPE_FREECB(peer, peerDestroy);
p = cbdataAlloc(peer);
p->http_port = CACHE_HTTP_PORT;
p->type = parseNeighborType(token);
- i = GetInteger();
-
- p->http_port = (u_short) i;
+ p->http_port = GetShort();
- i = GetInteger();
+ if (!p->http_port)
+ self_destruct();
- p->icp.port = (u_short) i;
+ p->icp.port = GetShort();
while ((token = strtok(NULL, w_space))) {
if (!strcasecmp(token, "proxy-only")) {
parse_ushortlist(ushortlist ** P)
{
char *token;
- int i;
+ u_short i;
ushortlist *u;
ushortlist **U;
while ((token = strtok(NULL, w_space))) {
- if (sscanf(token, "%d", &i) != 1)
- self_destruct();
-
- if (i < 0)
- i = 0;
-
+ i = GetShort();
u = xcalloc(1, sizeof(ushortlist));
-
- u->i = (u_short) i;
+ u->i = i;
for (U = P; *U; U = &(*U)->next)
void
ConfigParser::ParseUShort(u_short *var)
{
- int i;
-
- i = GetInteger();
-
- if (i < 0)
- i = 0;
-
- *var = (u_short) i;
+ *var = GetShort();
}
void
/* host:port */
host = token;
*t = '\0';
- port = (unsigned short) xatoi(t + 1);
+ port = xatos(t + 1);
if (0 == port)
self_destruct();
/* host:port */
host = token;
*t = '\0';
- port = (unsigned short) atoi(t + 1);
-
- if (0 == port)
- self_destruct();
- } else if ((port = atoi(token)) > 0) {
- /* port */
+ port = xatos(t + 1);
} else {
- self_destruct();
+ /* port */
+ port = xatos(token);
}
+ if (port == 0)
+ self_destruct();
+
s->s.sin_port = htons(port);
if (NULL == host)
s->vport = -1;
s->accel = 1;
} else if (strncmp(token, "vport=", 6) == 0) {
- s->vport = atoi(token + 6);
+ s->vport = xatos(token + 6);
s->accel = 1;
} else if (strncmp(token, "protocol=", 9) == 0) {
s->protocol = xstrdup(token + 9);