home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Spezial
/
SPEZIAL2_97.zip
/
SPEZIAL2_97.iso
/
ANWEND
/
ONLINE
/
SREFPRC1
/
READSTAT.SRF
< prev
next >
Wrap
Text File
|
1996-11-20
|
6KB
|
206 lines
/* return state info
SREF_READ_STATE: Get info on this request from a "temporary" file
!! Requires that the save_state variable be set equal to 1 !!
Syntax:
info=sref_read_state(state_var,occurence,thread,usefile)
Where:
i) state_var: a variable to extract information about
state_var can be one of the "internal" variables:
SEL = The selector (i.e.; DIR1/FOOBAR.HTM )
REQUEST = The full request string (i.e.; GET /DIR1/FOOBAR.HTM HTTP/1.0
SOURCE = The source/destination of the request
(i.e.; 209.121.65.122 80 2 154.33.123.55 1251)
CLIENT = The "client's numeric IP address" (extracted from source)
CLIENT_PORT = The client's port
CLIENT_NAME = The "clients name " (uses CLIENT address)
SERVER = The "server's numeric IP address (extracted from source)
SERVER_PORT = The server's port (extracted from source)
TRANSACTION = The transaction number
SERVER_NAME = IP name of server (the value of the servername() function)
THREAD = Thread id of this request
DATE_TIME = Time , date , and "julian date" of this request
(i.e.; 21:07:11,13 Nov 1996, 728975.879861)
or it can be one of the "request header" variables, such as:
ACCEPT, REFERER, USER-AGENT, AUTHORIZATION, HOST,
RANGE, MAINTAIN-CONNECTION, etc.
or a value set by a call to SREF_WRITE_STATE
Note that extracting one of the "header" variables will yield the
same result as the equivalent "Reqfield" GoServe function --
EXCEPT THAT POST-FILTER ACTIONS CAN NOT CALL GOSERVE FUNCTIONS!
So... you should use sref_read_state (along with a save_state=1
entry in SREFILTR.80) to obtain these variables "after GoServe has
responded to a request".
Also note that case does not matter, and you can optionally add a
colon after the state_var (i.e.; SEL, sel:, and Sel are equivalent)
ii) occurence (optional)
Useful if a "header" variable which may occur more then once is
desired. If occurence>1, then return the "occurence" instance
of state_var (if occurence is greater then the number of instance,
return a blank). If occurence=0, return number of instances
(0 if there are none). If occurence is not specified, return the
first instance.
iii) thread (optional)
thread-id to look up state information for. If not specified,
use the "own" thread. Note that information on whether the
thread is "still alive" is NOT returned (that is, this may be
left over from a much earlier request).
iv) Usefile (optional)
If given, the usefile should contain the absolute file name
of the cache file (the thread is NOT used if usefile is given).
Post-filter routines MUST supply a usefile when calling
sref_read_state (since the thread is dead!)
Notes:
* If no state_var is specified, a list of current "variables"
is returned (with repeated variables repeated).
* If no information has been saved (either because save_date<>1, or
because you've requested information on a thread that was never
used, or because you asked for a variable that has not been created
for this thread); an empty string is returned.
*/
sref_read_state:
crlf='0d0a'x
parse arg state_var,nth,athread,usefile
usefile=strip(usefile)
athread=strip(athread)
if nth="" then nth=1
if datatype(nth)<>'NUM' then nth=1
state_var=strip(upper(strip(state_var)),'t',':')
fooport=extract('serverport')
enmadd='SREF_'||fooport||'_'
ard=value(enmadd||'TEMPDATA_DIR',,'os2environment')
ard=strip(ard,'t','\')||'\'
if athread="" then
mytid=dostid()
else
mytid=athread
if usefile=' ' then
getfil=ard||'_T'||mytid||'.'||fooport
else
getfil=usefile
aa=stream(getfil,'c','query exists')
if aa="" then return ' '
wow=cvread(getfil,dastuff)
if wow=0 then do
return ' '
end
/* check creation date */
wow2=digits()
numeric digits 12
d1=date('b')
t1=time('m')/(24*60)
nowtime=d1+t1
eek1=dastuff.date_time
parse var eek1 foo ',' foo2 ',' thentime; thentime=strip(thentime)
mother=extract('LIMITTIMETOTAL')
maxtime=thentime+(mother/(24*60*60))
if maxtime<nowtime then do
numeric digits wow2
return ' ' /* too old! */
end
numeric digits wow2
/* is it one of the non-headers */
nonh="SEL REQUEST SOURCE THREAD DATE_TIME SERVER_NAME "
if wordpos(state_var,nonh)>0 then return dastuff.state_var
nonh2="CLIENT CLIENT_NAME CLIENT_PORT SERVER SERVER_PORT TRANSACTION "
isnonh2=wordpos(state_var,nonh2)
if isnonh2>0 then do
yeep='SOURCE'
gotval=dastuff.yeep
parse var gotval aserver aport atrans awho awhoport .
if state_var='SERVER' then return aserver
if state_var='SERVER_PORT' then return aport
if state_var='CLIENT' then return awho
if state_var='CLIENT_PORT' then return awhoport
if state_var='TRANSACTION' then return atrans
if state_var='CLIENT_NAME' then do
astat=sockgethostbyaddr(awho,'mstuff.!')
if astat=1 then
name1=strip(upper(mstuff.!name))
else
name1=awho
return name1
end
end
/* check in the request header list */
ith=0
namelist=" "
stuff=dastuff.!FUNGUS
do until stuff=""
parse var stuff a1 (crlf) stuff
parse var a1 aname ':' avalue ; aname=strip(upper(aname)); avalue=strip(avalue)
ith=ith+1
namelist=namelist||' '||aname
alist.ith.yname=upper(aname)
alist.ith.yvalue=avalue
end
/* if state_var, return list of variables (including header variables) */
if state_var=' ' then do
oo=cvtails(dastuff,alist22)
arf=" "
do mmm=1 to oo
if abbrev(alist22.mmm,'!')=1 then iterate
arf=arf||' '||alist22.mmm
end
return nonh||nonh2||namelist||arf
end
ict=0
gotval=' '
do jj=1 to ith
if alist.jj.yname<>state_var then iterate
ict=ict+1
if ict=nth then return alist.jj.yvalue
end
if nth=0 & ict>0 then return ict
/* is it one of the user written variables */
if symbol('DASTUFF.'||state_var)<>'VAR' then
return ' '
else
return dastuff.state_var