home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 10
/
amigaformatcd10.iso
/
-in_the_mag-
/
html_tutorial
/
mas_rec2.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1996-09-03
|
4KB
|
138 lines
// Record details about who the viewer of a web page is
//
// (C) M.A.Smith University of Brighton
//
// Permission is granted to use this code
// provided this declaration and copyright notice remains intact.
//
// 26 August 1995
#include "t99_type.h"
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
#include "parse.h"
#include "parse.cpp"
void write_log_entry( char[], char[] );
void cgi_var_output();
void gif_output( char [] );
char* getenv_n( char [] );
// Parameters to the CGI program
// passed in the QUERY_STRING environment variable
//
// file=mame - Names the file to which log information is written
// page=name - The name of the page that will be written to the log
// img=name - Names the image file which is returned
// - If no name or unreadable an image of a . is returned
// - If this parameter is omitted then a web page of CGI
// - variables is returned to help in debuging
// Remember all files name must be absolute or relative to the
// directory in which the CGI script is run
int main()
{
char *query_str = getenv("QUERY_STRING");
Parse list( query_str == 0 ?
"file=mas&page=test&img=" : query_str );
if ( list.get_item( "file" ) != NULL )
{
write_log_entry( list.get_item( "file", 1, true ),
list.get_item( "page" ) );
}
if ( list.get_item( "img" ) != NULL )
{
gif_output( list.get_item("img", 1, true) );
} else {
cgi_var_output(); // debug option
}
return 0;
}
void write_log_entry( char file[], char page[] )
{
}
void gif_output( char gif[] )
{
unsigned char square [] = {
'G', 'I', 'F', '8', '9', 'a',
0002, 0000, 0002, 0000, 0263, 0000, 0000, 0000, 0000, 0000,
0277, 0000, 0000, 0000, 0277, 0000, 0277, 0277,
0000, 0000, 0000, 0277, 0277, 0000, 0277, 0000,
0277, 0277, 0300, 0300, 0300, 0200, 0200, 0200,
0377, 0000, 0000, 0000, 0377, 0000, 0377, 0377,
0000, 0000, 0000, 0377, 0377, 0000, 0377, 0000,
0377, 0377, 0377, 0377, 0377, 0054, 0000, 0000,
0000, 0000, 0002, 0000, 0002, 0000, 0100, 0004,
0003, 0020, 0200, 0010, 0000, 0073 };
cout << "Content-type: image/gif" << "\n" << "\n";
if ( gif[0] != '\0' ) // Output gif file
{
ifstream in( gif );
if ( !in.fail() ) // Can read
{
char c;
in.read( &c, 1 );
while ( !in.eof() )
{
cout.write( &c, 1 );
in.read( &c, 1 );
}
return; // Finish
}
}
cout.write( square, sizeof( square ) );
}
// Debug option to deliver
// environment variables seen by the script
void cgi_var_output( )
{
cout << "Content-type: text/html" << "\n"
<< "\n" << "\n" << "<PRE>" << "\n";
cout << "AUTH_TYPE " << getenv_n( "AUTH_TYPE" ) << "\n";
cout << "CONTENT_LENGTH " << getenv_n( "CONTENT_LENGTH" ) << "\n";
cout << "CONTENT_TYPE " << getenv_n( "CONTENT_TYPE" ) << "\n";
cout << "GATEWAY_INTERFACE " << getenv_n( "GATEWAY_INTERFACE" ) << "\n";
cout << "HTTP_ACCEPT " << getenv_n( "HTTP_ACCEPT" ) << "\n";
cout << "HTTP_REFERER " << getenv_n( "HTTP_REFERER" ) << "\n";
cout << "HTTP_USER_AGENT " << getenv_n( "HTTP_USER_AGENT" ) << "\n";
cout << "PATH_INFO " << getenv_n( "PATH_INFO" ) << "\n";
cout << "PATH_TRANSLATED " << getenv_n( "PATH_TRANSLATED" ) << "\n";
cout << "QUERY_STRING " << getenv_n( "QUERY_STRING" ) << "\n";
cout << "REMOTE_ADDR " << getenv_n( "REMOTE_ADDR" ) << "\n";
cout << "REMOTE_IDENT " << getenv_n( "REMOTE_IDENT" ) << "\n";
cout << "REMOTE_HOST " << getenv_n( "REMOTE_HOST" ) << "\n";
cout << "REMOTE_USER " << getenv_n( "REMOTE_USER" ) << "\n";
cout << "REQUEST_METHOD " << getenv_n( "REQUEST_METHOD" ) << "\n";
cout << "SCRIPT_NAME " << getenv_n( "SCRIPT_NAME" ) << "\n";
cout << "SERVER_NAME " << getenv_n( "SERVER_NAME" ) << "\n";
cout << "SERVER_PORT " << getenv_n( "SERVER_PORT" ) << "\n";
cout << "SERVER_PROTOCOL " << getenv_n( "SERVER_PROTOCOL" ) << "\n";
cout << "SERVER_SOFTWARE " << getenv_n( "SERVER_SOFTWARE" ) << "\n";
cout << "</PRE>" << "\n";
}
char* getenv_n( char var[] )
{
char *p = getenv( var );
return p == NULL ? "[]" : p;
}