home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Spezial
/
SPEZIAL2_97.zip
/
SPEZIAL2_97.iso
/
ANWEND
/
ONLINE
/
SREFV12J
/
VIRTCHK.RXX
< prev
next >
Wrap
Text File
|
1997-07-23
|
9KB
|
343 lines
/* Check virtual dir module for SRE-FILTER. Uses contents of virtualfile
call with queue containing:
newq, newsem , SEL DEFDIR
returns
mapped_file_name (or 0 if error )
*/
parse upper arg stuff, usequeue , USESEM, max_semwait
parse upper var stuff virtualfile dlist
call pmprintf_sref(' SRE-FILTER virtual thread: virtualfile='||virtualfile)
virtualfile=strip(virtualfile)
standards=" !UPLOAD !CGI-BIN !ADDONS !HTML " /* shorthands used in limitation list */
mytid=dostid()
call pmprintf_sref(' SRE-FILTER virtual thread: queue='||usequeue)
call pmprintf_sref(' SRE-FILTER virtual thread: semaphore='||usesem)
call pmprintf_sref(' SRE-FILTER virtual thread: thread id ='||mytid)
resetit:
if virtualfile="" | usequeue="" | USESEM="" then do
call pmprintf_sref('SRE-FILTER virtual thread: initialization ERROR: '||usequeue)
exit
end
call set_virtual(virtualfile)
/*
do mm=1 to nvirtuals
call pmprintf_sref(virturl.mm||' == '||virtdir.mm' -- 'virtdir.mm.limitlist)
end
*/
if nvirtuals=0 then do
call pmprintf_sref(' SRE-FILTER virtual thread: Warning: No valid entries in virtual file:'||virtualfile)
end
else do
call pmprintf_sref(' SRE-FILTER virtual thread: #virtual dirs= '||nvirtuals)
end
/* Initialization now done == start waiting for requests for virtual info */
signal on error name iserror
signal on syntax name iserror
idid=0
bakme:
a=rxqueue('s',usequeue)
aq=queued()
if aq=0 then do
WOW=EVENTSEM_WAIT(USESEM,max_semwait)
aq=-1
if wow=640 then do
signal bakme
end
IF WOW<>0 THEN do /* FATAL ERROR */
call pmprintf_sref(' SRE-Filter Virtual Thread: fatal semaphore error: 'wow)
EXIT
end
end
wow=EVENTSEM_RESET(usesem)
if aq=-1 then
if queued()=0 then signal bakme
PARSE pull isit0
isit0=translate(isit0,' ','000d0a09'x)
if isit0=" " then signal bakme
/* die command? */
if abbrev(isit0,'*DIE*')=1 then
exit
goobs:
parse var isit0 idnum ',' newq ',' newsem ',' GOOFER
A=WORDS(GOOFER)
DEFDIR=STRIP(WORD(GOOFER,WORDS(GOOFER)))
ISIT=STRIP(DELWORD(GOOFER,WORDS(GOOFER)))
parse var idnum idnum host_nickname
host_nickname=strip(upper(host_nickname))
isitorig=isit
if newq="" | newsem="" then do
call pmprintf_sref(' SRE-FILTER virtual thread: missing queue or semaphore ')
exit
end
newq=upper(strip(newq)); newsem=upper(strip(newsem))
defdir=strip(defdir) ; isit=strip(isit)
if abbrev(isit,'*RESET*') then do
newfile=defdir
if newfile<>' ' then virtualfile=newfile
call set_virtual(virtualfile)
call pmprintf_sref(' SRE-Filter Virtual Thread:Reread virtual file: 'virtualfile)
end
else do
if isit=" " then
dog1=' 0 '
else do
isit=translate(isit,'\','/')
isit=strip(isit,'l','\')
defdir=translate(defdir,'\','/')
defdir=strip(defdir,,'\')
dog1=fig_virtual(isit,defdir,host_nickname)
end
a=rxqueue('s',newq)
push idnum ',' dog1
wow=eventsem_post(newsem)
end
signal bakme
iserror:
signal off error ; signal off syntax
foo=condition('d')
call pmprintf_sref(' SRE-FIlter: error in virtual thread 'SIGL','RC)
n1=queued()
a=rxqueue('d',usequeue)
a=rxqueue('c',usequeue)
foo=eventsem_reset(usesem)
a=eventsem_close(usesem)
a=eventsem_create(usesem)
a=rxqueue('s',newq)
push idnum ', 0 '
wow=eventsem_post(newsem)
call pmprintf_sref('SRE-Filter: done resetting virtual thread ')
signal on error name iserror
signal on syntax name iserror
signal bakme
exit
/*---------------------*/
fig_virtual:procedure expose virturl. virtdir. virtsubs. virthosts.
parse UPPER arg ACTION, ddir,host_nickname
ddir2=translate(ddir,'\','/')
ddir2=strip(ddir2,'t','\')||'\'
ACTION=STRIP(TRANSLATE(ACTION,'/','\'))
/* check for illegal action (with .. in it) */
if pos("..",action)>0 then return 0
gotit=0 ; starat=0
do ii =1 to virturl.0
if host_nickname<>virthosts.ii & virthosts.ii<>' ' then iterate
if virtdir.ii.limitlist>' ' then do
if wordpos(ddir2,virtdir.ii.limitlist)=0 then iterate
end
alabel=virturl.ii
if abbrev(action,upper(alabel))=1 then do
if length(alabel)< starat then iterate
t1=STRIP(delstr(action,1,length(alabel)))
t1=translate(t1,'\','/')
tadir=virtdir.ii
taupwd=virtdir.ii.!upwd
if VIRTsubs.ii=1 then do
gotit=1
adir=tadir
aupwd=taupwd
starat=length(alabel)
tryfile=adir||t1
iterate
end
else do
if pos('\',t1)>0 then do
iterate /* violation of no subdirs */
end
else do
gotit=1
adir=tadir
aupwd=taupwd
starat=length(alabel)
tryfile=adir||t1
iterate
end
end
end
end
/* append to data dir ? */
if gotit=0 then do
t1=strip(strip(translate(ddir,'\','/')),,'\')||'\'
action=translate(action,'\','/')
action=strip(action,'l','\')
tryfile=t1||action
end
tryfile=translate(tryfile,'\','/')
if pos('HTTP:',upper(tryfile))>0 & aupwd<>' ' then
tryfile=tryfile||' '||MK_BASE64(aupwd)
/*if gotit=1 then
call pmprintf_sref(" Virtual directory replacement yields: "|| tryfile)
*/
return tryfile /* success */
/* ---------------- */
/* read and set up virtual dir */
set_virtual:
parse arg afile
nvirtuals=0 ; virturl.0=0
a=sref_fileread(afile,'ulines',,'E') /* read it to a stem variable */
foo=do_extends(1)
if a=0 then do
call pmprintf_sref(' SRE-FILTER virtual thread: ERROR reading virtual-file: '||afile)
exit
end
do mm=1 to ulines.0
t1=strip(ulines.mm)
if t1="" then iterate
if abbrev(t1,';')=1 then iterate
tm1=strip(word(t1,1)) ; ahost=' '
if right(tm1,2)='//' then do
ahost=upper(left(tm1,length(tm1)-2))
parse var t1 foo t1a t1b t1c ',' upwd
end
else
parse var t1 t1a t1b t1c ',' upwd
upwd=strip(upwd); t1c=strip(t1c)
/* fix and addd / to candidate url */
t1a=strip(translate(strip(t1a),'/','\'),,'/')||'/'
t1b=strip(t1b) /* subdirectories ok ? */
subok=0
if right(t1b,1)='*' then do
t1b=left(t1b,length(t1b)-1)
subok=1
end
/* fix and add \ to candidate dir */
adir=strip(translate(strip(t1b),'\','/'),'t','\')||'\'
mdir=filespec('p',adir)
mdrv=filespec('d',adir)
if drv="" then drv=filespec('d',ddir)
t1b=mdrv||mdir
t4=" "
if t1c<>' ' then do
do mm9=1 to words(t1c)
tmp=upper(strip(word(t1c,mm9)))
/* check if tmp is one of the !standard items */
imu=wordpos(tmp,standards)
if imu>0 then tmp=strip(word(dlist,imu))
tmp=translate(tmp,'\','/')
tmp=strip(tmp,'t','\')||'\'
t4=t4||' '||upper(tmp)
end
end
nvirtuals=nvirtuals+1
virtsubs.nvirtuals=subok
virturl.nvirtuals=STRIP(TRANSLATE(t1a,' ','000D0A'X))
virtdir.nvirtuals=STRIP(t1b)
virtdir.nvirtuals.limitlist=t4
virtdir.nvirtuals.!upwd=upwd
virthosts.nvirtuals=ahost
end
virturl.0=nvirtuals
return 0
/************/
/* Redo ulines, by treating lines starting with , as continuation lines */
do_extends:procedure expose ulines.
if ulines.0=0 then return
isnew=1
tmps.1=ulines.1
do mm=2 to ulines.0
ali=strip(ulines.mm)
if abbrev(ali,',')=0 then do
isnew=isnew+1
tmps.isnew=ulines.mm
end
else do
tmps.isnew=tmps.isnew||substr(ali,2)
end
end
do mm=1 to isnew
ulines.mm=tmps.mm
end
ulines.0=isnew
return 0
/************/
/* create a base64 packing of a message */
mk_base64:procedure
do mm=0 to 25 /* set base 64 encoding keys */
a.mm=d2c(65+mm)
end /* do */
do mm=26 to 51
a.mm=d2c(97+mm-26)
end /* do */
do mm=52 to 61
a.mm=d2c(48+mm-52)
end /* do */
a.62='+'
a.63='/'
parse arg mess
s2=x2b(c2x(mess))
ith=0
do forever
ith=ith+1
a1=substr(s2,1,6,0)
ms.ith=x2d(b2x(a1))
if length(s2)<7 then leave
s2=substr(s2,7)
end /* do */
pint=""
do kk=1 to ith
oi=ms.kk ; pint=pint||a.oi
end /* do */
j1=length(pint)//4
if j1<>0 then pint=pint||copies('=',4-j1)
return pint