From c615ba7bdc7d0181f0e24f19d70e4697f863f69f Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 9 Oct 2014 18:24:26 +0000 Subject: switch to ctype --- livewatch/livewatch.c | 27 +++++++++++++-------------- 1 file 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 +#include #include #include #include @@ -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; } -- cgit v1.2.3