home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 35 Internet
/
35-Internet.zip
/
srev13h.zip
/
events.rxx
< prev
next >
Wrap
Text File
|
1999-10-31
|
9KB
|
279 lines
/* the sre-http event monitor daemon */
parse arg efile,icheck,serverport,servername
mytid=dostid()
call pmprintf(' SRE-http Events: thread, file, frequency='||mytid', 'efile', 'icheck)
oo=syssleep(60) /* sleep for 60 seconds (avoid startup problems */
esem='\SEM32\SREF_'serverport'_EVENT_CHECK'
oofbar:
foo=eventsem_create(esem,'P')
if foo<>0 & foo<>285 then do
call pmprintf(' SRE-http Events: ERROR, problem with semaphore 'esem' ('foo)
exit
end
towait=icheck*60*1000 /* minutes to wait */
/* endless loop --- wake up, check events, back to sleep */
do forever
foo=eventsem_wait(esem,towait)
if foo<>640 & foo<>0 then do
call pmprintf(' SRE-http Events: WARNING, bad status with semaphore 'esem' ('foo)
foo=eventsem_close(esem)
foo=eventsem_create(esem)
end
foo=eventsem_reset(esem) /* ignore multiple postings */
verbose=value('SREF_VERBOSE',,'os2environment')
if verbose>2 then call pmprintf(' SRE-http Events: checking event file 'efile)
istat=get_file(efile)
if istat=0 then do
oo=syssleep(icheck*60)
iterate
end
if verbose>3 then do
do mm=1 to events.0
call pmprintf(' SRE-http Event# 'mm ' 'events.!type.mm' = ' events.!type2.mm)
if events.!type3.mm<>'' then call pmprintf(' ... 'events.!type3.mm )
call pmprintf(' 'events.!action.mm ' == 'events.!action2.mm)
end
end
/* now check the events */
do mm=1 to events.0
aaction=events.!action.mm
atype=events.!type.mm
doretain=events.!retain.mm
if aaction=0 | atype=0 | atype='' | aaction='' then iterate /* bad event */
if verbose>3 then call pmprintf(' SRE-http Events: checking 'atype', 'aaction)
select
when atype='S' then do /* semaphore */
asem=events.!type2.mm
oof=eventsem_query(asem)
if oof<= 0 then iterate /* bad sem, or not posted */
end
when atype='F' then do
afile=stream(strip(events.!type2.mm),'c','query exists')
if afile='' then iterate /* no such file */
end
when atype='P' then do
aprocfile=events.!type2.mm
tproc='SRE_'||serverport||'_EVENT_A'
if macroquery(tproc)<>'' then foo=macrodrop(tproc)
foo=macroadd(tproc,aprocfile,'B')
if foo<>1 then do
call pmprintf(' SRE-http Events: WARNING: unable to use proc 'aprocfile)
iterate
end
interpret 'istat='tproc'('events.!type3.mm')'
if istat<>1 then iterate
end
otherwise iterate
end
if verbose>1 then call pmprintf(' SRE-http Events: doing #'mm': 'atype', 'aaction)
/* if here, this event has occured. Take an action */
aaction=events.!action.mm
select
when aaction='SUSPEND' then do
foo=value('SRE_SUSPEND',10,'os2environment')
end
when aaction='RESUME' then do
foo=value('SRE_SUSPEND',0,'os2environment')
end
when aaction='S' then do
foo=value('SRE_SHUTDOWN',10,'os2environment')
foo=get_request(servername,serverport,'!ping')
end
when aaction='R' then do
foo=value('SREF_REDO',1,'os2environment')
end
when aaction="I" then do
interpret events.!action2.mm
end
when aaction='E' then do
address cmd events.!action2.mm
end
when aaction='C' then do
parse var events.!action2.mm aprocfile arg
tproc='SRE_'||serverport||'_EVENT_B'
if macroquery(tproc)<>'' then foo=macrodrop(tproc)
foo=macroadd(tproc,aprocfile,'B')
if foo<>1 then do
call pmprintf(' SRE-http Events: WARNING: unable to perform proc 'aprocfile)
iterate
end
interpret 'istat='tproc'('arg')'
if istat<>1 then iterate
end
otherwise nop
end
/* clear semaphore or file? */
if doretain<>1 then do
if atype='S' then foo=eventsem_reset(asem)
if atype='F' then foo=sysfiledelete(afile)
end
end /* checking events */
/* done checking events, wait on esem */
end
/*********************/
/* read the efile into events. array
Structure of efile:
Event description are seperated by blank lines.
Lines beginning with ; are comments, and are ignored.
Event descriptions have two fields, a TYPE and an ACTION field.
type: FILE xxx, SEMAPHORE xxx, or PROCEDURE xx
action: RESET, SHUTDOWN, INTERPRET zzz, CALL zzz arglist , EXEC zzz
Example:
Type: SEMAPHORE \SEM32\SHUTDOWN_1
Action: shutdown
Type: F e:\goserve\flags\flag.1
Action: Call e:\goserve\flagdo.cmd 1
Type: Procedure check_time
Action: interpret atime=time('n') ;
adate=date('n') ;
call pmprintf("Today's date is: "||atime||' '||adate)
*/
get_file:procedure expose events.
parse arg efile
events.=0
ikk=stream(efile,'c','query size')
if ikk='' | ikk=0 then do
call pmprintf(' SRE-http Events: WARNING: bad event file: 'efile
return 0
end
stuff=charin(efile,1,ikk)
foo=stream(efile,'c','close')
do until stuff='' /* read entire file */
/* remove comments and blank lines preceeding a block */
do until stuff=''
parse var stuff a1 '0d0a'x stuff
a1=strip(a1)
if abbrev(a1,';')=1 | a1='' then iterate
stuff=a1||'0d0a'x||stuff
leave
end
/* now at beginning of a block */
if stuff='' then leave /* no more events specified */
/* read lines until next blank line */
ii=events.0+1
do until stuff=''
parse var stuff a1 '0d0a'x stuff ;a1=strip(a1)
if abbrev(a1,';')=1 then iterate
if a1='' then leave
ta1=translate(a1)
select
when abbrev(ta1,'TYPE:')=1 then do
parse var a1 . ':' atype events.!type2.ii events.!type3.ii
atype=translate(atype)
select
when wordpos(atype,'S SEMAPHORE SEM')>0 then do
atype='S'
if abbrev(translate(strip(events.!type2.ii)),'\SEM32\')=0 then do
call pmprintf(' SRE-http Events: WARNING: bad Semaphore TYPE: 'a1)
atype=0
end
end
when wordpos(atype,'F FILE')>0 then atype='F'
when wordpos(atype,'P PROCEDURE PROC')>0 then atype='P'
otherwise do
call pmprintf(' SRE-http Events: WARNING: bad TYPE: 'a1)
atype=0
end
end
events.!type.ii=atype
end
when abbrev(ta1,'RETAIN:')=1 then do
parse var ta1 . ':' aa
if wordpos(strip(aa),'1 YES Y')>0 then events.!retain.ii=1
end
when abbrev(ta1,'ACTION:')=1 then do
parse var a1 . ':' aaction events.!action2.ii
aaction=translate(aaction)
select
when wordpos(aaction,'RESUME')>0 then aaction='RESUME'
when wordpos(aaction,'SUSPEND')>0 then aaction='SUSPEND'
when wordpos(aaction,'SHUTDOWN S SHUT')>0 then aaction='S'
when wordpos(aaction,'RESET R')>0 then aaction='R'
when wordpos(aaction,'CALL C')>0 then aaction='C'
when wordpos(aaction,'EXECUTE EXEC E')>0 then aaction='E'
when wordpos(aaction,'INTERPRET INTER I INTERP')>0 then aaction='I'
otherwise do
call pmprintf(' SRE-http Events: WARNING: bad ACTION: 'a1)
aaction=0
end
end
events.!action.ii=aaction
end
otherwise do
if events.!action.ii<>'' then do
events.!action2.ii=events.!action2.ii' 'a1
end
else do
call pmprintf(' SRE-http Events: WARNING: Bad line ignore = 'a1)
end
end /* otherwise */
end /* select */
end /* stuff='' */
if events.!type.ii<>0 then events.0=ii /* if action found, then augment counter */
end /* get next block */
return 1
/***********/
/* hit me */
get_request:procedure
crlf='0d0a'x
parse arg servername,sport,message
crlf ='0d0a'x
family ='AF_INET'
httpport=sport
rc=sockgethostbyname(servername, 'serv.0'); dotserver=serv.0addr
if rc=0 then return 0
gosaddr.0family=family ;gosaddr.0port=httpport;gosaddr.0addr =dotserver
gosock = SockSocket(family, 'SOCK_STREAM', 'IPPROTO_TCP')
message='GET /'request' HTTP/1.0'crlf
message=message||crlf
rc = SockConnect(gosock,'gosaddr.0')
if rc<0 then return 0
rc = SockSend(gosock, message)
do r=1 by 1
rc = SockRecv(gosock, 'response', 1000)
got=got||response
if rc<=0 then leave
end r
rc = SockClose(gosock)
return length(got)