home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / srev13g.zip / sredomd5.cmd < prev    next >
OS/2 REXX Batch file  |  1998-10-12  |  3KB  |  139 lines

  1. /* Compute md5, for sre-http, daemon.
  2.    Contains an internal array for retaining prior results.
  3.    This is meant to be invoked by srefmon.cmd -- it is not
  4.    to be run in standalone mode.
  5. */
  6.  
  7. SIGNAL ON SYNTAX NAME WOW ; SIGNAL ON ERROR NAME WOW
  8. parse arg stuff
  9. parse var stuff dmnname cachelen watchpid
  10. call pmprintf(" stuff " stuff)
  11. verbose=1 
  12.  
  13. if dmnname='' then do
  14.   say "This is an SRE-http daemon -- it is not meant to be run in standalone mode"
  15.   exit
  16. end
  17.  
  18. apid=dospid()
  19.  
  20. incache=0
  21. nentries=0
  22. call pmprintf("SRE-http MD5 daemon ("dmnname") on "apid" w\cache size= "cachelen)
  23. say " This is the SRE-http MD5 daemon (on pid "apid
  24. say " Notes:"
  25. say "  a) This will terminate when GoServe (on "watchpid") terminates"
  26. say "  b) If you terminate this process, Content-MD5 headers will be suppressed "
  27.  
  28. do forever
  29.  
  30.   foo=dosprocinfo('N',watchpid)
  31.   if foo='' then do
  32.      call pmprintf('SRE-http MD5 daemon: exiting')
  33.      exit
  34.   end
  35.  
  36.   foo=sref_dmn_wait('MD5_DMN_SREF',16)  
  37.   if foo='' then DO
  38.      if incache>cachelen then incache=clean_cache(cachelen)   /* remove old entries */
  39.      iterate
  40.   end
  41.  
  42.   afile=upper(sref_dmn_value(foo))
  43.   if afile="*PID*" then do
  44.       foo=sref_dmn_reply(foo,apid)
  45.       iterate
  46.   end
  47.  
  48.   nowtime=stream(afile,'c','query datetime')
  49.   if nowtime='' then do
  50.      call pmprintf('SRE-http MD5 daemon: no such file 'afile)
  51.      iterate
  52.   end
  53.  
  54. /* see if it's in storage */
  55.    eek=csh.afile
  56.    storeme=1
  57.    if abbrev(eek,'CSH.')=0 then do /* in storage */
  58.       parse var eek nn','wastime','eek 
  59.       if wastime<>nowtime then do
  60.          nop
  61.       end
  62.       else do
  63.          storeme=0
  64.          nn=nn+1
  65.          csh.afile=nn||','||wastime||','||eek
  66.          if verbose>1 then call pmprintf(' SRE-http md5: using old value for 'afile)
  67.       end
  68.    end
  69.    if storeme=1 then do
  70.         eek=fig_md5(afile)
  71.         CSH.afile='1,'||nowtime||','||eek
  72.         incache=incache+1
  73.         if verbose>1 then call pmprintf(' SRE-http md5: storing value for 'afile)
  74.         if incache>cachelen then incache=clean_cache(cachelen)   /* remove old entries */
  75.    end
  76.    fii=sref_dmn_reply(foo,eek)
  77.    if fii<>1 then call pmprintf('SRE-http md5 daemon: error processing 'afile '='fii)
  78. end
  79.  
  80.  
  81. exit
  82.  
  83.  
  84.  
  85. /*************/
  86. /* clean up cache */
  87. clean_cache:procedure expose csh.  csh2.
  88. parse arg clen
  89.  
  90. foo=cvtails(CSH,ALIST)
  91. todrop=clen*0.33
  92. minbeat=0
  93. didrop=0
  94. say "Attempting to drop "todrop " from " clen
  95. do forever
  96.   minbeat=minbeat+1
  97.   do mm=1 to alist.0
  98.      atail=alist.mm
  99.      if atail='' then iterate
  100.      parse var csh.atail nn',' .
  101.      if nn = minbeat then do
  102.        drop csh.atail ;alist.mm=''
  103.        didrop=didrop+1
  104.       end
  105.      if didrop>todrop then leave  /* got rid of enough ? */
  106.   end
  107.  
  108.   if didrop>todrop then leave  /* else, get rid of some more */
  109. end
  110.  
  111. say " Cache cleaned (dropped entries= "didrop
  112. return (clen-didrop)
  113.  
  114.  
  115. WOW:
  116. CALL PMPRINTF("SRE-HTTP SREDOMD5.CMD ERROR AT " SIGL' 'RC)
  117. EXIT
  118.  
  119.  
  120. /* make md5 using srx_md5 */
  121.  
  122.  
  123. /***********/
  124. fig_md5:procedure
  125.  
  126. parse arg afile
  127.  
  128.     isz=stream(afile,'c','query size')
  129.     foo=stream(afile,'c','open read')
  130.     in1=charin(afile,1,isz)
  131.     foo=stream(afile,'c','close')
  132.     a32=srx_md5(in1)
  133.  
  134. return a32
  135.  
  136.  
  137.  
  138.  
  139.