home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 35 Internet
/
35-Internet.zip
/
srev13g.zip
/
ALIASCHK.RXX
< prev
next >
Wrap
Text File
|
1999-06-24
|
13KB
|
499 lines
/* Check aliases module for SRE-http. Uses contents of aliasfile
To call: set queue/sempahore with:
newqueue,newsem,OLDURL
Returns
match , newurl
If match=0. then no match (and newurl=oldurl)
*/
parse upper arg aliasfile, usequeue , USESEM, max_semwait,sport
mytid=dostid()
foo=pmprintf_sref(' SRE-http Alias: thread, file and queue: 'mytid ', 'aliasfile', 'usequeue,,sport)
cfgs_dir=value('SRE_CFGS_DIR',,'os2environment')
cfglist_file=cfgs_dir||'\CFGLIST.CFG'
defrealm=value('SREF_DEFREALM_FILE_TEMP',,'os2environment')
resetit:
if usequeue="" | USESEM="" then do
call pmprintf('SRE-http Alias ERROR: initialization ERROR: '||usequeue)
exit
end
call set_alias(aliasfile)
foo=pmprintf_sref(' SRE-http Alias: #aliases= '||naliases,,sport)
/* Initialization now done == start waiting for requests for alias info */
signal on error name iserror
signal on syntax name iserror
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(' SRE-http Alias ERROR: fatal semaphore error ')
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
parse var isit0 idnum ',' newq ',' newsem ',' ISIT
parse var idnum idnum host_nickname
isitorig=isit
if newq="" | newsem="" then do
foo=pmprintf_sref(' SRE-http Alias ERROR: missing queue or semaphore ',,sport)
signal bakme
end
newq=upper(strip(newq)); newsem=upper(strip(newsem))
ISIT=STRIP(ISIT)
if abbrev(isit,'*LIST*') then do
dog1=''
do mm=1 to aliases.0
dog1=dog1||aliashosts.mm '// 'aliases.mm||'0d0a'x
end
a=rxqueue('s',newq)
push idnum ',' dog1
wow=eventsem_post(newsem)
signal bakme
end
if abbrev(isit,'*RESET*') then do
parse var isit foo newfile .
if newfile<>' ' then aliasfile=newfile
call set_alias(aliasfile)
foo=pmprintf_sref(' SRE-http Alias reset: #aliases= '||naliases,,sport)
end
else do
if naliases=0 then do
dog1=' 0 '||isitorig
end
else do
if pos('?',isit)>0 then do
parse var isit a1 '?' a2
isit=translate(a1,'/','\')
isit=strip(isit,'l','/')||'?'||a2
end
dog1=fig_alias(isit,host_nickname)
end
a=rxqueue('s',newq)
push idnum ',' dog1
wow=eventsem_post(newsem)
end
signal bakme
iserror:
signal off error ; signal off syntax
call pmprintf(' SRE-http Aliase ERROR: error in alias thread 'sigl)
a=rxqueue('d',usequeue)
a=rxqueue('c',usequeue)
a=eventsem_close(usesem)
a=eventsem_create(usesem)
a=rxqueue('s',newq)
push idnum ', 0 '
wow=eventsem_post(newsem)
call pmprintf('SRE-http Alias ERROR: done resetting alias thread ')
signal on error name iserror
signal on syntax name iserror
signal bakme
exit
/* ---------- */
fig_alias:procedure expose aliases. aliashosts.
parse arg inline , host_nickname,isit0
isdebug=0
host_nickname=strip(upper(host_nickname))
inline=strip(inline)
if abbrev(inline,'++:')=1 then do
inline=substr(inline,4)
isdebug=1
end
inline=strip(strip(inline),'l','/')
sel=translate(inline,' ','000d0a09'x)
doexact=0
gotit=0 ; resu=' ';tsel=upper(sel); gotit2=''
/* superceding host specific matches first? */
if abbrev(host_nickname,'_!')=1 then do /* check superceding-host specific matches first */
do m=1 to aliases.0
if host_nickname<>aliashosts.m then iterate /* not for this host */
jlias=aliases.m
parse var jlias jlias1 .
aresu=sref_wild_match(tsel,jlias1,resu)
if aresu=0 then iterate /* no match */
if aresu=-1 then do /* exact match */
resu=-1
gotit=m
gotit2=jlias
leave
end
resu=aresu
GOTIT=M
gotit2=jlias
iterate
end
end
/* no host specfic and not "strict-superceding host", try a generic match? */
if gotit=0 & abbrev(host_nickname,'_!!')=0 then do
do m=1 to aliases.0
if abbrev(host_nickname,'_!')=1 & aliashosts.m<>'' then iterate /* do not check superceding hosts */
if (aliashosts.m<>'' & aliashosts.m<>host_nickname) then iterate
jlias=aliases.m
parse var jlias jlias1 .
aresu=sref_wild_match(tsel,jlias1,resu)
if aresu=0 then iterate /* no match */
if aresu=-1 then do /* exact match */
resu=-1
gotit=m
gotit2=jlias
leave
end
resu=aresu
GOTIT=M
gotit2=jlias
iterate
end
end
select
when gotit=0 then usesel=inline /* no match, use original */
when resu=-1 then do /* exact match, use candidate as is */
parse var aliases.gotit . usesel
end
otherwise do /* wildcard match */
parse var aliases.gotit . jlias1 ; jlias1=strip(jlias1)
if pos('*',jlias1)=0 then do /* no wildcards in candidate */
usesel=jlias1
end
else do /* fill in * appropriately */
psel=sel
do il=1 to words(resu)
psel=overlay(' ',psel,strip(word(resu,il)))
end
arf='';idog=0 ; jlias2=jlias1
do until jlias2=""
parse var jlias2 a1 '*' jlias2
arf=arf||a1
if jlias2<>' ' then do
idog=idog+1
if idog<=words(psel) then arf=arf||strip(word(psel,idog))
end
else do
if right(jlias1,1)='*' then do
idog=idog+1
if idog<=words(psel) then arf=arf||strip(word(psel,idog))
end
leave
end /* parse on * */
end /* scanning jlias2 */
usesel=space(arf,0)
end /* fill in wildcards */
end /* otherwise */
end /*select */
/* fix up / */
parse var usesel k1 '?' k2
k1=translate(k1,'/','\')
if pos('?',usesel)>0 then
usesel=k1||'?'||k2
else
usesel=k1
if isdebug=1 then gotit=STRIP(gotit)':'gotit2
return gotit ' ' usesel
/* ---------------- */
/* read and set up aliases */
set_alias:
parse arg afile
naliases=0
aliases.0=0
a=sref_fileread(afile,'ulines',,'E') /* read it to a stem variable */
foo=do_extends(1)
oo=stream(afile,'c','close')
if a=0 then do
foo=pmprintf_sref(' SRE-http Alias ERROR: ERROR reading user-file: '||afile,,sport)
return
end
foo=add_cfglist('ALIAS','ALIASES.IN') /*augment the ulines stem variable, using CFGLIST.CFG files */
foo=add_defrealm('ALIAS') /* augment from DEFREALM_TEMP_FILE */
exton=0
do mm=1 to ulines.0
t1=translate(ulines.mm,' ','0d0a09'x)
t1=strip(t1)
if exton=1 then do
t1=t1storage||t1
end
exton=0
if t1="" then iterate
if abbrev(t1,';')=1 then iterate
if right(t1,2)=' ,' & mm < ulines.0 then do
exton=1
t1=left(t1,length(t1)-2)
t1storage=strip(t1)
iterate
end
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
end
else
parse var t1 t1a t1b
if pos('?',t1a)>0 then do
parse var t1a q1 '?' q2
t1a=strip(translate(q1,'/','\'),'l','/')||'?'||q2
end
else do
t1a=strip(translate(t1a,'/','\'),'l','/')
end
if pos('?',t1b)>0 then do
parse var t1b q1 '?' q2
t1b=strip(translate(q1,'/','\'),'l','/')||'?'||q2
end
else do
t1b=strip(translate(t1b,'/','\'),'l','/')
end
naliases=naliases+1
aliases.naliases=upper(t1a)||' '||t1b
aliashosts.naliases=ahost
end
aliases.0=naliases
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
/**********************************/
/* Add entries to ulines. variable, from the defrealm_temp file.
Note that this file only has the appropriate port entries
in it */
add_defrealm:procedure expose defrealm ulines.
parse upper arg atype
atype=strip(atype)
crlf='0d0a'x
/* call pmprintf(' xxx 'atype' 'defrealm) */
if defrealm='' then return 0
aa=sref_open_read(defrealm,15,'READ')
if aa<=0 then return 0
ii=stream(defrealm,'c','query size')
if ii=0 | ii='' then return 0
stuff=charin(defrealm,1,ii)
foo=stream(defrealm,'c','close')
do forever
if stuff="" then return 1
parse var stuff aline (crlf) stuff
if abbrev(aline,';')=1 then iterate
parse var aline btype ':' aline
if btype<>atype then iterate
ii=ulines.0+1
ulines.ii=aline
ulines.0=ii
end
/**********************************/
/* Add entries to ulines. variable, from the ATYPE files listed in the CFGLIST.CFG file
(but only for port SPORT)
*/
add_cfglist:procedure expose ulines. cfglist_file sport cfgs_dir
parse upper arg atype,defname
atype=strip(atype)
if cfglist_file='' then return /* nothing to do */
/* look for files */
foo=translate(stream(cfglist_file,'c','open read'))
if abbrev(foo,'READY')<>1 then do
call pmprintf('SRE-http: ' atype ' Warning: Unable to open cfglist.cfg ')
return 0 /* unable to open */
end
inj=stream(cfglist_file,'c','query size')
if inj=0 | inj='' then return 0 /* empty file */
astuff=charin(cfglist_file,1,inj)
foo=stream(cfglist_file,'c','close')
crlf='0d0a'x
astuff=astuff||crlf||' ' /* place an elephant in cairo */
/* determine which files apply to this atype and port, by readling CFGLIST.CFG */
mm=0
/* note: file is organized in blocks */
curport=80 /* defaults port and host */
curhost=''
curfile=''
do forever /* for all blocks in file */
if astuff='' then leave /* all done (note we always put an elephant in cairo */
parse var astuff aline (crlf) astuff
if abbrev(aline,';')=1 then iterate /* ignore comments */
if aline='' then do /* block end */
if curport<>sport | curfile='' then do /* different port, or this atype file not specified */
nop
end
else do /* otherwise, add this entry to filelist */
mm=mm+1
ufiles.mm.!host=curhost
ufiles.mm.!file=curfile
end
curport=80 ; curhost='' ; curfile='' /* clear block */
iterate
end
/* process an entry in this block */
parse upper var aline ltype ':' lstuff ;ltype=strip(ltype) ; lstuff=strip(lstuff)
select
when ltype='PORT' then curport=lstuff
when ltype='HOST' then curhost=lstuff
when abbrev(ltype,atype)=1 then do
curfile=strip(translate(lstuff,'\','/'),'l','\')
if pos(':',curfile)=0 then curfile=cfgs_dir||'\'||curfile
end
when ltype='*' then do
curfile=strip(translate(lstuff,'\','/'),,'\')
if pos(':',curfile)=0 then curfile=cfgs_dir||'\'||curfile
curfile=stream(curfile'\'defname,'c','query exists')
end
otherwise nop
end
end
/* done reading cfglist; add entries from appropriate files */
if mm=0 then return 1 /* no auxillary files of this type */
ufiles.0=mm
do mm=1 to ulines.0 /* retain old uline */
ulisttmp.mm=ulines.mm
end
ulisttmp.0=ulines.0
do mm=1 to ufiles.0
afile=ufiles.mm.!file
ahost=ufiles.mm.!host
a=sref_fileread(afile,'ulines',,'E') /* read it to a stem variable */
if a=0 | ulines.0=0 then do
call pmprintf(' SRE-http 'atype': WARNING**: bad auxillary file: '||afile)
iterate
end
foo=do_extends(1) /* fixup ulines. */
call pmprintf('SRE-http 'atype': adding from 'AHOST ' specific file 'afile ',' ulines.0)
do ii=1 to ulines.0
aline=strip(ulines.ii)
if ALINE=' ' then iterate
aline=translate(aline,' ','0009'x)
if abbrev(strip(aline),';')=1 then iterate
parse var aline aw1 .
if pos('//',aw1)>0 then do
call pmprintf('SRE-http: 'atype 'warning: disallowed auxillary entry: 'aline)
iterate
end
if ahost<>'' then aline=ahost||'// '||aline
ii2=ulisttmp.0+1
ulisttmp.ii2=aline
ulisttmp.0=ii2
end
end
do mm=1 to ulisttmp.0
ulines.mm=ulisttmp.mm
end
ulines.0=ulisttmp.0
drop ulisttmp.
return 1