71056f5afc99b24edeb3fb082ac703a5388b2995
[citadel.git] / webcit / braindamage.c
1 #include <stdlib.h>
2 #include <unistd.h>
3 #include <stdio.h>
4 #include <ctype.h>
5 #include <string.h>
6 #include <errno.h>
7 #include <sys/stat.h>
8 #include <stdarg.h>
9 #include "webcit.h"
10 #include "child.h"
11
12 /*
13  * browser_braindamage_check()
14  * 
15  * Given the value of the HTTP "User-agent:" directive supplied by
16  * a web browser, determine using a local configuration file whether
17  * the browser is capable of handling WebCit's frames/JavaScript mode.
18  *
19  * This function returns one of the following values:
20  * B_YES        (Yes, it's ok to use frames and JavaScript)
21  * B_NO         (No, fall back to the noframes version)
22  * B_ASK        (We don't know; ask the user)
23  */
24
25 int browser_braindamage_check(char *browser)
26 {
27         FILE *fp;
28         char buf[256];
29         int thisval;
30
31         fp = fopen("static/braindamage", "r");
32         if (fp == NULL)
33                 return (B_ASK);
34
35         while (fgets(buf, 256, fp) != NULL) {
36                 buf[strlen(buf)-1] = 0;
37                 thisval = (-1);
38                 if (!strncasecmp(buf, "YES", 3)) {
39                         thisval = B_YES;
40                         strcpy(buf, &buf[3]);
41                 } else if (!strncasecmp(buf, "NO", 2)) {
42                         thisval = B_NO;
43                         strcpy(buf, &buf[2]);
44                 } else if (!strncasecmp(buf, "ASK", 3)) {
45                         thisval = B_ASK;
46                         strcpy(buf, &buf[3]);
47                 }
48                 if (thisval >= 0) {
49                         while (isspace(buf[0])) strcpy(buf, &buf[1]);
50                         if (wildmat(buf, browser)) {
51                                 return(thisval);
52                         }
53                 }
54         }
55
56         fclose(fp);
57         return (B_ASK);
58 }