summaryrefslogtreecommitdiffstats
path: root/cgi/cgiuseragent.c
diff options
context:
space:
mode:
Diffstat (limited to 'cgi/cgiuseragent.c')
-rw-r--r--cgi/cgiuseragent.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/cgi/cgiuseragent.c b/cgi/cgiuseragent.c
new file mode 100644
index 0000000..e1aa0a2
--- /dev/null
+++ b/cgi/cgiuseragent.c
@@ -0,0 +1,52 @@
+/*
+** Copyright 2000 Double Precision, Inc.
+** See COPYING for distribution information.
+*/
+
+/*
+*/
+
+#include "cgi.h"
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+extern void error(const char *);
+
+int cgi_useragent(const char *p)
+{
+ const char *c=getenv("HTTP_USER_AGENT");
+
+ for ( ; c && *c; c++)
+ {
+ size_t i;
+
+ if (isalpha((int)(unsigned char)*c))
+ continue;
+
+ for (i=0; p[i]; i++)
+ {
+ int a,b;
+
+ a=(unsigned char)p[i];
+ b=(unsigned char)c[i+1];
+ if (!b)
+ break;
+
+ a=toupper(a);
+ b=toupper(b);
+ if (a != b)
+ break;
+ }
+
+ if (p[i] == 0)
+ {
+ int b=(unsigned char)c[i+2];
+
+ if (b == 0 || !isalpha(b))
+ return (1);
+ }
+ }
+ return (0);
+}