summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2012-01-13 15:25:08 +0000
committerDimitri Sokolyuk <demon@dim13.org>2012-01-13 15:25:08 +0000
commit4965539b45f92af70e70f9a3d0897f44c56c2dde (patch)
tree03ccc91b204c5d8e8c195866af22cb8eab583885
parentae9d3afe45d24ead7f95288ffc626a4f74430448 (diff)
cosmetic changes
-rw-r--r--livewatch/livewatch.c36
1 files 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 <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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;
}