FILE: |
agent.c |
PURPOSE: |
load different html documents based on agent |
AUTHOR: |
Russell Berrett |
DATE: |
October 4, 1995 |
LAST UPDATED: |
October 19, 1995 |
Copyright 1995 SurfUtah.Com.
Permission granted to copy, modify, and otherwise use this code
in
whatever manner you see fit, with no warranty expressed or implied.
Please retain this notice; this is the only restriction. If
you
make any changes to the original code, please credit yourself
so
that SurfUtah.Com is not asked to maintain versions of code
that
were not developed by SurfUtah.Com.
SURFUTAH.COM GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
SOFTWARE
AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
WARRANTY
OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR
PURPOSE.
#include
#include
#include
#define TRUE 1
#define FALSE 0
/* add other agents here */
typedef enum {mozilla2_0, mozilla1_1, mozilla1_0, ms_explorer,
other_agent} agenttype;
/*-------------------------------*/
int main(int argc, char *argv[])
{
agenttype theagent;
char *cptr = NULL, filename[512], agent[512];
FILE *fptr = NULL;
int character;
printf("Content-type: text/html\n\n");
sprintf(agent, "%s", getenv("HTTP_USER_AGENT"));
/* check to see which type of agent is making request */
cptr = strstr(agent, "Mozilla");
if (cptr) { cptr += 8; if (strncmp("2.0", cptr, 3)
<= 0)
theagent = mozilla2_0;
else if (strncmp("1.1", cptr, 3) <= 0)
theagent = mozilla1_1;
else
theagent = mozilla1_0;
}
else if (strstr(agent, "Microsoft Internet Explorer"))
{
theagent = ms_explorer;
}
else {
theagent = other_agent;
}
/* assign a filename based on the agent */
switch (theagent) {
case mozilla2_0:
/* ideally we should have a filename that would have some kind
of HTML source with frames, but I don't so I'll just let it
run into Mozilla1.1 */
case mozilla1_1:
strcpy(filename, "/usr/local/etc/httpd/htdocs/home.html");
break;
case ms_explorer:
/* Microsoft has some really cool stuff like embedded avi. It
would be nice if I had something like that, but since I don't-
I'll just let it run down to the non-enhanced */ case mozilla1_0:
/* no table support in Netscape 1.0 */
case other_agent:
strcpy(filename, "/usr/local/etc/httpd/htdocs/home_ne.html");
break;
}
fptr = fopen(filename, "r");
character = fgetc(fptr);
while (character != EOF) {
printf("%c", (char)character);
character = fgetc(fptr);
}
fclose(fptr);
} /* main */ /
*----------------------------------------------------*/
/* eof */ |