home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 35 Internet
/
35-Internet.zip
/
srev13h.zip
/
puburchk.rxx
< prev
next >
Wrap
Text File
|
1999-11-11
|
10KB
|
401 lines
/* Check public urls module for SRE-http. Uses contents of puburlfile
and queues & semaphores to communicate with filter.
Returns 0, or matching public url
*/
parse upper arg purlfile, usequeue , USESEM, max_semwait,sport
/*
call pmprintf_sref(' SRE-http public-url thread: using='||purlfile)
call pmprintf_sref(' SRE-http public-url thread: queue='||usequeue)
call pmprintf_sref(' SRE-http public-url thread: semaphore='||usesem)
*/
mytid=dostid()
foo=pmprintf_sref(' SRE-http Publicurl: thread, file, queue='||mytid', 'purlfile', 'usequeue,,sport)
cfgs_dir=value('SRE_CFGS_DIR',,'os2environment')
cfglist_file=cfgs_dir||'\CFGLIST.CFG'
crlf='0d0a'x
defrealm=value('SREF_DEFREALM_FILE_TEMP',,'os2environment')
resetit:
if usequeue="" | USESEM="" then do
call pmprintf('SRE-http Publicurl ERROR: initialization ERROR: '||usequeue)
exit
end
npurls=set_purls(purlfile)
foo=pmprintf_sref(' SRE-http Publicurl: #public-urls = ' npurls)
call value 'SREF_NUM_PURLS',npurls,'os2environment'
/* Initialization now done == start waiting for requests for public url 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 Publicurl 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
call pmprintf(' SRE-http Publicurl ERROR: missing queue or semaphore ')
signal bakme
end
newq=upper(strip(newq)); newsem=upper(strip(newsem))
ISIT=STRIP(ISIT)
if abbrev(isit,'*LIST*') then do
dog1=''
do kk=1 to purls.0
t1=purls.!l.kk
dog1=dog1||t1||crlf
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 purlfile=newfile
call set_purls(purlfile)
foo=call pmprintf_sref(' SRE-http Publicurl thread reset: #public-urls = ' npurls)
end
else do
if npurls=0 then do
dog1=0
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_purl(isit,host_nickname)
end
a=rxqueue('s',newq)
push idnum ',' dog1
wow=eventsem_post(newsem)
end
signal bakme
iserror: /* jump here on an error */
signal off error ; signal off syntax
call pmprintf_sref(' Error in daemon ('usequeue'), exiting: 'sigl','rc)
a=rxqueue('d',usequeue)
call pmprintf(" Status= "a " shutting down "usequeue)
a=eventsem_close(usesem)
call pmprintf(" Status= "a " shutting down "usesem)
foo=value('SREF_REDO',1,'os2environment')
badt=value('SREF_PUBURL_BAD',1,'os2environment')
exit
/* ---------- */
fig_purl:procedure expose purls. wildpurls. usesem usequeue
parse upper arg needle,hostn
needle=strip(needle,'l','/')
if hostn<>'' then needle=upper(strip(hostn))'//'needle
needle=upper(strip(needle))
if length(needle)<=purls.!maxlen then do
if upper(purls.needle)<>upper('PURLS.'needle) then do
return purls.needle
end
end
/* check wildcards -- retain "best" match */
oldresu='' ;isit=0
do ii=1 to wildpurls.0
resu=sref_wild_match(needle,wildpurls.ii,oldresu)
if resu=-1 then do
isit=ii
leave
end
if resu=0 then iterate
isit=ii
oldresu=resu
end
if isit>0 then
return wildpurls.isit.!value
else
return 0
/* ---------------- */
/* read and set up public-url*/
set_purls:procedure expose purls. wildpurls. cfglist_file cfgs_dir sport defrealm
parse arg afile
npurls=0
a=sref_fileread(afile,'ulines',,'E') /* read it to a stem variable */
oo=stream(afile,'c','close')
if a=0 then do
call pmprintf(' SRE-http Publicurl: could not read (empty file?) '||afile)
ulines.0=0
end
foo=add_cfglist('PUBURLS','PUBURLS.IN') /*augment the ulines stem variable, using CFGLIST.CFG files */
foo=add_defrealm('PUBURLS')
drop purls. ; drop wildpurls.
purls.!maxlen=0
purls.0=0
wildpurls.0=0
ii=0
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
str=t1a' 't1b
t1a=ahost'//'t1a
end
else do
parse var t1 t1a t1b
str=t1a' 't1b
end
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
/* this is only used for *LIST* */
ipj=purls.0+1
tt1a=t1a
if pos('//',t1a)=0 then tt1a=' //'tt1a
purls.!l.ipj=tt1a' 't1b
purls.0=ipj
t1a=upper(t1a)
if pos('*',t1a)>0 then do
amm=wildpurls.0+1
wildpurls.amm.!value=str
wildpurls.amm=t1a
wildpurls.0=amm
end
else do
purls.t1a=str
purls.!maxlen=max(purls.!maxlen,length(str))
end
ii=ii+1
end
return ii
/**********************************/
/* 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
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_file)
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 */
ULINEStmp.mm=ulines.mm
end
ULINEStmp.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
call pmprintf(' SRE-http '||lower(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=ULINEStmp.0+1
ULINEStmp.ii2=aline
ULINEStmp.0=ii2
end
end
do mm=1 to ULINEStmp.0
ulines.mm=ULINEStmp.mm
end
ulines.0=ULINEStmp.0
drop ULINEStmp.
return 1