/*
 * README
 *
 * Copyright (c) 2001 Network Appliance, Inc.
 * All rights reserved.
 */

ICAP Server 1.0 

Compilation instructions:
1) Solaris: make -f Makefile.sol
2) Linux:   make
3) Windows: edit "#undef WINDOWS" to "#define WINDOWS" in iserver.h
            Use main.mak with nmake. Use main.dsw with Microsoft Visual C++ 6.0
	    to develop in the Windows enviornment 

Running instructions:
iserver10 [-p <port>] [-v] [-t <num_threads>] [-te]
	  [-cp <reqmod_cache_percent>] [-mp <modify_percent>]

port: port at which iserver10 will accept connections (default 1344)
-v: verbose mode for debugging (default is off)
num_threads: number of threads that the iserver spawns to handle connections
	     (default 10)
-te: Support for trailers (default is off)
-cp: Percentage of REQMOD requests that should be returned as ICAP-cachable
     (default is 0)
-mp: Percentage of RESPMOD Preview requests that are responded to with a 200 OK
     (default is 100)

Description:

This ICAP 1.0 Server is used by default to echo back the contents of 
an ICAP REQMOD or RESPMOD request or provide an OPTIONS reply in case of 
an OPTIONS request. It supports only the chunked encoding format for data 
as specified by the ICAP1.0 draft.

Sample request-response examples are as shown below -
(Note: all lines are terminated by a '\r\n'. Blank lines correspond
to a '\r\n'. The request and response messages are delimited by '---'
for illustration. Message body formats are described instead of being
literally and redundantly depicted. 

1) OPTIONS

Request from ICAP Client to ICAP server:
---------------------------------------------------------------------
OPTIONS icap://cherryhill.eng.netapp.com:1344/virus_checking ICAP/1.0
Server-rhdr : Host: cherryhill.eng.netapp.com:1344

---------------------------------------------------------------------

Response from ICAP Server to ICAP Client:
---------------------------------------------------------------------
ICAP/1.0 200 OK
ISTAG: "5BDEEEA9-12E4-2"
Server: XYZ Technology Virus Scanning Software 5.0 ( XYZT 5.0 )
Max-Connections: 1000
Methods: RESPMOD, REQMOD, LOG, OPTIONS
Options-TTL: 300

---------------------------------------------------------------------

2) RESPMOD (w/o Preview)

Request from ICAP Client to ICAP server:
---------------------------------------------------------------------
RESPMOD icap://cherryhill.eng.netapp.com:1344/virus_checking ICAP/1.0
Encapsulated: req-hdr=0 res-hdr=341 res-body=578
 
GET / HTTP/1.1
Host: www.google.com
Connection: keep-alive
User-Agent: Mozilla/4.72 [en] (WinNT; U)
Pragma: no-cache
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*
Accept-Encoding: gzip
Accept-Language: en
Accept-Charset: iso-8859-1,*,utf-8
Cookie: PREF=ID=6f64a0970a9df2ea:TM=978561529:LM=978561529

HTTP/1.0 200 OK
Date: Wed, 18 Apr 2001 17:55:37 GMT
Content-Length: 1953
Content-Type: text/html
Proxy-Connection: keep-alive
Server: GWS/1.10
Via: 1.1 viv1 (NetCache NetApp//n/ronco/build/scratch/viv/vivmain.1682.025_17_25_48)

<chunk size in hex>\r\n
<data with bytes=chunk size>\r\n
\r\n

<chunk size in hex>\r\n
<data with bytes=chunk size>\r\n
\r\n

0\r\n
\r\n
---------------------------------------------------------------------

Response from ICAP Server to ICAP Client:
---------------------------------------------------------------------
ICAP/1.0 200 OK
ISTAG: "5BDEEEA9-12E4-2"

HTTP/1.0 200 OK
Date: Wed, 18 Apr 2001 18:06:05 GMT
Content-Length: 1953
Content-Type: text/html
Proxy-Connection: keep-alive
Server: GWS/1.10
Via: 1.1 viv1 (NetCache NetApp//n/ronco/build/scratch/viv/vivmain.1682.025_17_25_48)

<sizeof all chunks in hex>\r\n
<data>\r\n
0\r\n
\r\n
---------------------------------------------------------------------

3) RESPMOD (with Preview)

Request from ICAP Client to ICAP server:
---------------------------------------------------------------------
RESPMOD icap://cherryhill.eng.netapp.com:1344/virus_checking ICAP/1.0
Preview: 1024
Encapsulated: req-hdr=0 res-hdr=341 res-body=578
TE: trailers
 
GET / HTTP/1.1
Host: www.google.com
Connection: keep-alive
User-Agent: Mozilla/4.72 [en] (WinNT; U)
Pragma: no-cache
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*
Accept-Encoding: gzip
Accept-Language: en
Accept-Charset: iso-8859-1,*,utf-8
Cookie: PREF=ID=6f64a0970a9df2ea:TM=978561529:LM=978561529
 
HTTP/1.0 200 OK
Date: Wed, 18 Apr 2001 18:10:52 GMT
Content-Length: 1953
Content-Type: text/html
Proxy-Connection: keep-alive
Server: GWS/1.10
Via: 1.1 viv1 (NetCache NetApp//n/ronco/build/scratch/viv/vivmain.1682.025_17_25_48)

400\r\n
<1024 bytes of preview Data>\r\n
0\r\n
\r\n
---------------------------------------------------------------------

Intermediate Response from ICAP Server:
---------------------------------------------------------------------
ICAP/1.0 100 Continue
---------------------------------------------------------------------

Remaining Request from ICAP Client:
---------------------------------------------------------------------
<chunk size in hex>\r\n
<data with bytes=chunk size>\r\n
\r\n

<chunk size in hex>\r\n
<data with bytes=chunk size>\r\n
\r\n

0\r\n
\r\n
---------------------------------------------------------------------

Final Response from ICAP Server to ICAP Client:
---------------------------------------------------------------------
ICAP/1.0 200 OK
ISTAG: "5BDEEEA9-12E4-2"

HTTP/1.0 200 OK
Date: Wed, 18 Apr 2001 18:06:05 GMT
Content-Length: 1953
Content-Type: text/html
Proxy-Connection: keep-alive
Server: GWS/1.10
Via: 1.1 viv1 (NetCache NetApp//n/ronco/build/scratch/viv/vivmain.1682.025_17_25_48)

<sizeof all chunks in hex>\r\n
<data>\r\n
0\r\n
Cache-Control: no-cache\r\n
Connection: close\r\n
\r\n
---------------------------------------------------------------------

4) REQMOD (w/o Preview)

Request from ICAP Client to ICAP server:
---------------------------------------------------------------------
REQMOD icap://cherryhill.eng.netapp.com:1344/virus_checking ICAP/1.0
Host: cherryhill.eng.netapp.com:1344
Encapsulated: req-hdr=0
Client-IP: 10.34.25.90
Server-IP: 216.239.37.100
 
GET http://www.google.com/ HTTP/1.0
Host: www.google.com
User-Agent: Mozilla/4.72 [en] (WinNT; U)
Pragma: no-cache
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*
Accept-Encoding: gzip
Accept-Language: en
Accept-Charset: iso-8859-1,*,utf-8
Cookie: PREF=ID=6f64a0970a9df2ea:TM=978561529:LM=978561529
Via: 1.0 viv1 (NetCache NetApp//n/ronco/build/scratch/viv/vivmain.1682.025_17_25_48)
X-Forwarded-For: 10.34.25.90
 
---------------------------------------------------------------------

Response from ICAP Server to ICAP Client:
---------------------------------------------------------------------
ICAP/1.0 200 OK
Host: cherryhill.eng.netapp.com:1344
Encapsulated: req-hdr=0
Client-IP: 10.34.25.90
Server-IP: 216.239.37.100

GET http://www.google.com/ HTTP/1.0
Host: www.google.com
User-Agent: Mozilla/4.72 [en] (WinNT; U)
Pragma: no-cache
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*
Accept-Encoding: gzip
Accept-Language: en
Accept-Charset: iso-8859-1,*,utf-8
Cookie: PREF=ID=6f64a0970a9df2ea:TM=978561529:LM=978561529
Via: 1.0 viv1 (NetCache NetApp//n/ronco/build/scratch/viv/vivmain.1682.025_17_25_48)
X-Forwarded-For: 10.34.25.90

---------------------------------------------------------------------

An "API" is provided for inserting code to provide ICAP functionality other
than echo. api.h contains the interfaces that are used by the ICAP server
to echo back content. The routines are invoked as follows:
1) api_options_response: An OPTIONS request is recvd.
2) api_log_request: A LOG request is recvd.
3) api_preview_reqmod: A REQMOD request with Preview is recvd. 
4) api_preview_respmod: A RESPMOD request with Preview is recvd. 
5) api_modify_reqmod: The entire REQMOD request is recvd.
6) api_modify_respmod: The entire RESPMOD request is recvd.

Notes:

1) api.c: file "options.conf" contains the options response to be sent back 
   to client. Note that the IS-TAG to be sent back in each response is read 
   from the second line of this file
2) connections are left open (persistent) by default to improve performance. 
   Set #define CLOSECONN in iserver.h to 0 inorder to close connection after 
   each request is processed (easier to debug)
3) For RESPMOD, only one chunk is sent back for the entire body to be
   echoed back
4) Use api.c to add your implementations for respmod, reqmod, options
   and logging
5) Address bugs, suggestions, comments to viv@netapp.com

API (Filtering, etc) Info:
1) By default the API functions as an echo server for respmod, reqmod
   and reads the options from the "options.conf" file

2) VALLEY GIRL Filter: 
   a) Edit api_filter.h to replace "#undef FILTER"
      to "#define FILTER". Edit Makefile or Makefile.sol to replace
      "EXEC = iserver10" with "EXEC = iserver10 filter"   
   b) compile on linux or solaris (not available for windows)
   c) the http respmod text should be valley girl filtered. bugs
      exist for certain web sites (eg. www.cmu.edu)
   d) modify valspeak.l to get creative with the filtering rules      

3) BANNER STRIPPING:
   a) Edit banner_stripper.h to replace "#undef BANNER_STRIPPER"
      to "#define BANNER_STRIPPER". Edit Makefile to replace
      "API = api_filter" with "API = banner_stripper"
   b) compile for linux (not available for Solaris or Windows)
   c) Banners that dont meet the 14 standard sizes (+/- 5 pixels 
      in length and width) are replaced by netapp.gif (contoured/warped 
      to fit as per html source). #define NOGIFS in banner_stripper.c to 
      replace legal sized gifs with broken links instead.
