[dnsmasq PATCH 1/2] Move common parsing functions to utils.c
- From: Dan Williams <dcbw redhat com>
- To: Mathieu Trudel-Lapierre <mathieu tl gmail com>
- Cc: Mathieu menubar gnome org, mathieu-tl ubuntu com, Trudel-Lapierre <mathieu trudel-lapierre canonical com>, networkmanager-list gnome org
- Subject: [dnsmasq PATCH 1/2] Move common parsing functions to utils.c
- Date: Fri, 17 Aug 2012 17:29:54 -0500
---
src/dnsmasq.h | 8 +++++-
src/option.c | 92 -----------------------------------------------------------
src/util.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 98 insertions(+), 94 deletions(-)
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
index b131c96..660ee89 100644
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
@@ -891,9 +891,15 @@ void safe_pipe(int *fd, int read_noblock);
void *whine_malloc(size_t size);
int sa_len(union mysockaddr *addr);
int sockaddr_isequal(union mysockaddr *s1, union mysockaddr *s2);
-int hostname_isequal(char *a, char *b);
+int hostname_isequal(const char *a, const char *b);
time_t dnsmasq_time(void);
int is_same_net(struct in_addr a, struct in_addr b, struct in_addr mask);
+char *split_chr(char *s, char c);
+char hide_meta(char c);
+char unhide_meta(char cr);
+void unhide_metas(char *cp);
+int atoi_check(char *a, int *res);
+int atoi_check16(char *a, int *res);
#ifdef HAVE_IPV6
int is_same_net6(struct in6_addr *a, struct in6_addr *b, int prefixlen);
u64 addr6part(struct in6_addr *addr);
diff --git a/src/option.c b/src/option.c
index 22c08e7..f2ee306 100644
--- a/src/option.c
+++ b/src/option.c
@@ -380,49 +380,6 @@ static struct {
{ 0, 0, NULL, NULL, NULL }
};
-/* We hide metacharaters in quoted strings by mapping them into the ASCII control
- character space. Note that the \0, \t \b \r \033 and \n characters are carefully placed in the
- following sequence so that they map to themselves: it is therefore possible to call
- unhide_metas repeatedly on string without breaking things.
- The transformation gets undone by opt_canonicalise, atoi_check and opt_string_alloc, and a
- couple of other places.
- Note that space is included here so that
- --dhcp-option=3, string
- has five characters, whilst
- --dhcp-option=3," string"
- has six.
-*/
-
-static const char meta[] = "\000123456 \b\t\n78\r90abcdefABCDE\033F:,.";
-
-static char hide_meta(char c)
-{
- unsigned int i;
-
- for (i = 0; i < (sizeof(meta) - 1); i++)
- if (c == meta[i])
- return (char)i;
-
- return c;
-}
-
-static char unhide_meta(char cr)
-{
- unsigned int c = cr;
-
- if (c < (sizeof(meta) - 1))
- cr = meta[c];
-
- return cr;
-}
-
-static void unhide_metas(char *cp)
-{
- if (cp)
- for(; *cp; cp++)
- *cp = unhide_meta(*cp);
-}
-
static void *opt_malloc(size_t size)
{
void *ret;
@@ -455,28 +412,6 @@ static char *opt_string_alloc(char *cp)
return ret;
}
-
-/* find next comma, split string with zero and eliminate spaces.
- return start of string following comma */
-
-static char *split_chr(char *s, char c)
-{
- char *comma, *p;
-
- if (!s || !(comma = strchr(s, c)))
- return NULL;
-
- p = comma;
- *comma = ' ';
-
- for (; *comma == ' '; comma++);
-
- for (; (p >= s) && *p == ' '; p--)
- *p = 0;
-
- return comma;
-}
-
static char *split(char *s)
{
return split_chr(s, ',');
@@ -502,33 +437,6 @@ static char *canonicalise_opt(char *s)
return ret;
}
-static int atoi_check(char *a, int *res)
-{
- char *p;
-
- if (!a)
- return 0;
-
- unhide_metas(a);
-
- for (p = a; *p; p++)
- if (*p < '0' || *p > '9')
- return 0;
-
- *res = atoi(a);
- return 1;
-}
-
-static int atoi_check16(char *a, int *res)
-{
- if (!(atoi_check(a, res)) ||
- *res < 0 ||
- *res > 0xffff)
- return 0;
-
- return 1;
-}
-
static void add_txt(char *name, char *txt)
{
size_t len = strlen(txt);
diff --git a/src/util.c b/src/util.c
index a1d47d6..320d4cf 100644
--- a/src/util.c
+++ b/src/util.c
@@ -280,7 +280,7 @@ int sa_len(union mysockaddr *addr)
}
/* don't use strcasecmp and friends here - they may be messed up by LOCALE */
-int hostname_isequal(char *a, char *b)
+int hostname_isequal(const char *a, const char *b)
{
unsigned int c1, c2;
@@ -581,3 +581,93 @@ int read_write(int fd, unsigned char *packet, int size, int rw)
return 1;
}
+/* find next comma, split string with zero and eliminate spaces.
+ return start of string following comma */
+
+char *split_chr(char *s, char c)
+{
+ char *comma, *p;
+
+ if (!s || !(comma = strchr(s, c)))
+ return NULL;
+
+ p = comma;
+ *comma = ' ';
+
+ for (; *comma == ' '; comma++);
+
+ for (; (p >= s) && *p == ' '; p--)
+ *p = 0;
+
+ return comma;
+}
+
+/* We hide metacharaters in quoted strings by mapping them into the ASCII control
+ character space. Note that the \0, \t \b \r \033 and \n characters are carefully placed in the
+ following sequence so that they map to themselves: it is therefore possible to call
+ unhide_metas repeatedly on string without breaking things.
+ The transformation gets undone by opt_canonicalise, atoi_check and opt_string_alloc, and a
+ couple of other places.
+ Note that space is included here so that
+ --dhcp-option=3, string
+ has five characters, whilst
+ --dhcp-option=3," string"
+ has six.
+*/
+
+static const char meta[] = "\000123456 \b\t\n78\r90abcdefABCDE\033F:,.";
+
+char hide_meta(char c)
+{
+ unsigned int i;
+
+ for (i = 0; i < (sizeof(meta) - 1); i++)
+ if (c == meta[i])
+ return (char)i;
+
+ return c;
+}
+
+char unhide_meta(char cr)
+{
+ unsigned int c = cr;
+
+ if (c < (sizeof(meta) - 1))
+ cr = meta[c];
+
+ return cr;
+}
+
+void unhide_metas(char *cp)
+{
+ if (cp)
+ for(; *cp; cp++)
+ *cp = unhide_meta(*cp);
+}
+
+int atoi_check(char *a, int *res)
+{
+ char *p;
+
+ if (!a)
+ return 0;
+
+ unhide_metas(a);
+
+ for (p = a; *p; p++)
+ if (*p < '0' || *p > '9')
+ return 0;
+
+ *res = atoi(a);
+ return 1;
+}
+
+int atoi_check16(char *a, int *res)
+{
+ if (!(atoi_check(a, res)) ||
+ *res < 0 ||
+ *res > 0xffff)
+ return 0;
+
+ return 1;
+}
--
1.7.11.2
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]