home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 35 Internet
/
35-Internet.zip
/
srev13h.zip
/
srealm.rxx
< prev
next >
Wrap
Text File
|
2001-03-15
|
9KB
|
319 lines
/* Daemon to check for superceding realm entries */
parse upper arg defrealm_file_temp, usequeue , USESEM, max_semwait,sport
mytid=dostid()
foo=pmprintf_sref(' SRE-http S_Realm: thread, file and queue: 'mytid ', 'defrealm_file_temp', 'usequeue,,sport)
resetit:
if usequeue="" | USESEM="" then do
call pmprintf('SRE-http S_Realm ERROR: initialization ERROR: '||usequeue)
exit
end
call set_realm(defrealm_file_temp)
oo=value('SREF_NO_SUPERCEDING_REALM','0 '||realms.0,'os2environment')
foo=pmprintf_sref(' SRE-http S_Realm: #superceding realms= '||realms.0,,sport)
/* Initialization now done == start waiting for requests for realm 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 S_Realm 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 S_Realm 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 realms.0
dog1=dog1||realms.mm.!host'// 'realms.mm.!realm' 'realms.mm||'0d0a'x
end
a=rxqueue('s',newq)
push idnum ',' dog1
wow=eventsem_post(newsem)
signal bakme
end
if abbrev(isit,'*RESET*') then do
call set_realm(defrealm_file_temp)
oo=value('SREF_NO_SUPERCEDING_REALM','0 '||realms.0,'os2environment')
foo=pmprintf_sref(' SRE-http S_Realm reset: #superceding realms= '||realms.0,,sport)
end
else do
if realms.0=0 then do
dog1=' '
end
else do
dog1=fig_realms(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_SREALM_BAD',1,'os2environment')
exit
/* ---------- */
fig_realms:procedure expose realms. xrealms. usesem usequeue
parse arg isit , host_nickname,isit0
crlf='0d0a'x
isit=strip(isit,'l','/')
if pos('?',isit)>0 then do
parse var isit a1 '?' a2
a1=translate(a1,'/','\')
tsel=a1'?'||a2
end
else do
tsel=translate(isit,'/','\')
end
tsel=strip(translate(tsel))
host_nickname=strip(upper(host_nickname))
doexact=0
gotit=0 ; resu=' '; gotit2=''
/* is this an exact match, for a specific host? */
if length(tsel)<70 & (pos('*',tsel)+pos('?',tsel)=0) & host_nickname<>'' then do
al=host_nickname'//'tsel
gotit=xrealms.al
end
/* not an exact match, check superceding host specific matches first? */
if gotit=0 then do
if abbrev(host_nickname,'_!')=1 then do /* check superceding-host specific matches first */
do m=1 to realms.0
if realms.m.!x=1 then iterate /* not an exact match */
if host_nickname<>realms.m.!host then iterate /* not for this host */
jlias=strip(realms.m)
aresu=sref_wild_match(tsel,jlias,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
end
/* no host specfic and not "strict-superceding host", try a generic match? */
if gotit=0 & abbrev(host_nickname,'_!!')=0 then do
/* is this an exact match, default host? */
if length(tsel)<70 & (pos('*',tsel)+pos('?',tsel)=0) then do
al='//'tsel
gotit=xrealms.al
end
if gotit=0 then do
do m=1 to realms.0
if realms.m.!x=1 then iterate /* not an exact match */
if abbrev(host_nickname,'_!')=1 & realms.m.!host>'' then iterate /* do not check superceding hosts */
if (realms.m.!host<>'' & realms.m.!host<>host_nickname) then iterate
jlias=strip(realms.m)
aresu=sref_wild_match(tsel,jlias,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
end
if gotit=0 then return '' /* no match */
if pos('*',gotit2)=0 then do
dalias=realms.gotit.!alias
end
else do
dalias=sref_wildcard(tsel,gotit2' 'realms.gotit.!alias,0)
parse var dalias ii ' , 'dalias
if ii=0 then return dalias='' /* should never happen */
end
oof=realms.gotit.!realm||crlf||realms.gotit.!origrule||crlf
oof=oof||realms.gotit.!access||crlf||dalias||crlf
oof=oof||realms.gotit.!puburls||crlf||realms.gotit.!virtual
return oof
/* ---------------- */
/* read and set up aliases */
set_realm:
parse arg defrealm
realms.=''
realms.0=0
crlf='0d0a'x
do mm=1 to 20
aa=sref_open_read(defrealm,15,'READ')
if aa<=0 then do
if mm=20 then do
call pmprintf(' SRE-http SREALM: Final WARNING: unable to open ('aa') 'defrealm)
return 0
end
else do
call pmprintf(' SRE-http SREALM: #'mm' WARNING: unable to open ('aa') 'defrealm)
call syssleep(10)
iterate /* try again */
end
end
leave /* if here, okay */
end
ii=stream(defrealm,'c','query size')
if ii=0 | ii='' then do
call pmprintf(' SRE-http SREALM: WARNING, bad size ('aa') 'defrealm)
return 0
end
stuff=charin(defrealm,1,ii)
foo=stream(defrealm,'c','close')
/* skip first two lines */
parse var stuff . (crlf) . (crlf) stuff
do forever
if stuff="" then leave
parse var stuff aline (crlf) stuff
if abbrev(aline,';C_REALM')=1 then do
parse var aline . rname . 'rule=' arule
iat=realms.0+1
realms.0=iat
realms.iat=arule
realms.iat.!origrule=arule
realms.iat.!realm=rname
realms.iat.!alias='' ;realms.iat.!puburls=0 ;realms.iat.!alias=0
realms.iat.!virtual=0
do forever /* get alias access puburls virtual */
if stuff='' then leave
parse var stuff aline (crlf) stuff
if aline='' then leave
parse var aline atype ':' ainfo ; atype=strip(translate(atype))
parse var ainfo ahost .
if right(strip(ahost),2)='//' then do
parse var ainfo realms.iat.!host '//' ainfo
end
aatype='!'||atype
if atype<>'VIRTUAL' then parse var ainfo . ainfo /* get rid of rule */
realms.iat.aatype=ainfo
end
end
else do /* scan till next blank line */
do forever
if stuff='' then leave
parse var stuff aline (crlf) stuff
if aline='' then leave
end
end
end
/* clean up rules, and create list of exact entries */
xrealms.=0
do mm=1 to realms.0
arr=realms.mm
arr=translate(strip(realms.mm))
arr=strip(arr,'l','/')
if pos('?',arr)>0 then do
parse var arr a1 '?' a2
a1=translate(a1,'/','\')
arr=a1'?'||a2
end
else do
arr=translate(arr,'/','\')
end
realms.mm=arr
if pos('*',arr)>0 | pos('?',arr)>0 | length(arr)>50 then iterate
realms.mm.!x=1
arr=strip(realms.mm.!host)'//'arr
xrealms.arr=mm
end
/*
do mm=1 to realms.0
call pmprintf(mm' 'realms.mm.!realm' 'realms.mm.!host'//--'realms.mm' == 'realms.mm.!alias)
end
*/
return 1