summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2014-10-09 18:24:26 +0000
committerDimitri Sokolyuk <demon@dim13.org>2014-10-09 18:24:26 +0000
commitc615ba7bdc7d0181f0e24f19d70e4697f863f69f (patch)
tree0fcfbc67c3a63b9d8c5c9f7764467139b30471ff
parent2c1e88ef678c5df683a8226fa57cf6b0d3f2fbcb (diff)
switch to ctype
-rw-r--r--livewatch/livewatch.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/livewatch/livewatch.c b/livewatch/livewatch.c
index 52c2ad2..35f9571 100644
--- a/livewatch/livewatch.c
+++ b/livewatch/livewatch.c
@@ -1,6 +1,7 @@
/* $Id$ */
#include <err.h>
+#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -8,22 +9,19 @@
int
valid(char *s)
{
- char hex[] = "0123456789abcdef";
+ int i;
- if (strlen(s) != 32)
- return 0;
-
- do
- if (!strchr(hex, *s))
+ for (i = 32; *s; i--, s++)
+ if (!isascii(*s) || !isxdigit(*s))
return 0;
- while (*++s);
- return 1;
+ return !i;
}
int
main()
{
+ char *answer = "Alles OK";
char *s, *p;
if (!(s = getenv("QUERY_STRING")))
@@ -32,14 +30,15 @@ main()
printf("Content-type: text/html\r\n\r\n");
if ((s = strstr(s, "key="))) {
- if ((p = strchr(s, '&')))
- *p = '\0';
-
s += 4;
+ p = strchr(s, '&');
+ if (p)
+ *p = '\0';
if (valid(s))
- printf("%s", s);
- } else
- printf("Alles OK");
+ answer = s;
+ }
+
+ printf("%s", answer);
return 0;
}