From 4965539b45f92af70e70f9a3d0897f44c56c2dde Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Fri, 13 Jan 2012 15:25:08 +0000 Subject: cosmetic changes --- livewatch/livewatch.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/livewatch/livewatch.c b/livewatch/livewatch.c index 671e5de..52c2ad2 100644 --- a/livewatch/livewatch.c +++ b/livewatch/livewatch.c @@ -1,20 +1,22 @@ /* $Id$ */ +#include #include #include #include int -test(char *s) +valid(char *s) { - char valid[] = "0123456789abcdef"; + char hex[] = "0123456789abcdef"; if (strlen(s) != 32) return 0; - while (*s) - if (!strchr(valid, *s++)) + do + if (!strchr(hex, *s)) return 0; + while (*++s); return 1; } @@ -24,24 +26,20 @@ main() { char *s, *p; - s = getenv("QUERY_STRING"); + if (!(s = getenv("QUERY_STRING"))) + errx(1, "not a CGI context"); - if (s) { - printf("Content-type: text/html\r\n\r\n"); + printf("Content-type: text/html\r\n\r\n"); - s = strstr(s, "key="); + if ((s = strstr(s, "key="))) { + if ((p = strchr(s, '&'))) + *p = '\0'; - if (s) { - s += 4; - p = strchr(s, '&'); - if (p) - *p = '\0'; - - if (test(s)) - printf("%s", s); - } else - printf("Alles OK"); - } + s += 4; + if (valid(s)) + printf("%s", s); + } else + printf("Alles OK"); return 0; } -- cgit v1.2.3