/****************************************************************************
* *
* FILE: agent.c *
* *
* PURPOSE: load different html documents based on agent *
* *
* AUTHOR: Russell Berrett *
* *
* DATE: October 4, 1995 *
* *
* LAST UPDATED: June 29, 1996 *
* *
* *
* 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 <stdio.h >
#include <stdlib.h >
#include <string.h >
#define TRUE 1
#define FALSE 0
/* add other agents here */
typedef enum {mozilla3_0, mozilla2_0, mozilla1_1, mozilla1_0,
msie2_0, msie3_0, other_agent} agenttype;
/*--------------------------------------------------*/
int main(int argc, char *argv[])
{
agenttype theagent;
char *cptr = NULL, location[512], agent[512];
FILE *fptr = NULL;
int character;
sprintf(agent, "%s", getenv("HTTP_USER_AGENT"));
/* check to see which type of agent is making request */
cptr = strstr(agent, "Mozilla");
if (cptr) {
if (strstr(agent, "MSIE 3.0")) {
theagent = msie3_0;
}
else if (strstr(agent, "MSIE 2.0")) {
theagent = msie2_0;
}
else { /* pure Netscape */
cptr += 8;
if (strncmp("3.0", cptr, 3) <= 0)
theagent = mozilla3_0;
else 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 {
theagent = other_agent;
}
/* assign a location based on the agent */
switch (theagent) {
case msie3_0:
case msie2_0:
/* MSIE supports some things Netscape does not like
floating frames, embedded AVI, and background sound.
Basically it is just a Netscape look alike. */
case mozilla3_0:
/* let is run into Netscape 2.0;
case mozilla2_0:
/* ideally we should have a location 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(location, "/www/htdocs/contrib/cgi/agent/home.html");
break;
case mozilla1_0:
/* no table support in Netscape 1.0 */
case other_agent:
strcpy(location, "/www/htdocs/contrib/cgi/agent/home_ne.html");
break;
}
printf("Content-type: text/html\n\n");
fptr = fopen(location, "r");
character = fgetc(fptr);
while (character != EOF) {
printf("%c", (char)character);
character = fgetc(fptr);
}
fclose(fptr);
} /* main */
/*----------------------------------------------------------------------*/
/* eof */
|