Back to index

courier  0.68.2
cgiuseragent.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 2000 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 /*
00007 */
00008 
00009 #include      "cgi.h"
00010 #include      <stdio.h>
00011 #include      <string.h>
00012 #include      <stdlib.h>
00013 #include      <ctype.h>
00014 
00015 extern void error(const char *);
00016 
00017 int cgi_useragent(const char *p)
00018 {
00019        const char *c=getenv("HTTP_USER_AGENT");
00020 
00021        for ( ; c && *c; c++)
00022        {
00023               size_t i;
00024 
00025               if (isalpha((int)(unsigned char)*c))
00026                      continue;
00027 
00028               for (i=0; p[i]; i++)
00029               {
00030                      int a,b;
00031 
00032                      a=(unsigned char)p[i];
00033                      b=(unsigned char)c[i+1];
00034                      if (!b)
00035                             break;
00036 
00037                      a=toupper(a);
00038                      b=toupper(b);
00039                      if (a != b)
00040                             break;
00041               }
00042 
00043               if (p[i] == 0)
00044               {
00045                      int b=(unsigned char)c[i+2];
00046 
00047                      if (b == 0 || !isalpha(b))
00048                             return (1);
00049               }
00050        }
00051        return (0);
00052 }