home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / srev13h.zip / prerep.cmd < prev    next >
OS/2 REXX Batch file  |  1999-11-15  |  4KB  |  136 lines

  1. /* sample of an SRE-http "pre reply" procedure -- add a servername/time tag (or
  2.   response header) to all responses.
  3.  
  4. General Info:  
  5. Pre-reply  procedures ares called (by SRE) as:
  6.   stuff=sref_prereply_proc(contents,fileflag,mimetype,modstring)
  7. where
  8.   contents = the actual contents to be sent to the client, or the fully
  9.              qualified file name
  10.    fileflag = 1 if this is a file, 0 if this is actual contents, 2 if "sref_multsend" contents
  11.  mimetype = the mime type For example, image/gif or text/plain.
  12.   clen    = content-length (might be missing)
  13.  modstring = a string to should use to signal "new mimetype"
  14.  
  15. This procedure should return either
  16.    ''   == when the procedure responds to the client (using 'FILE or 'VAR Goserve commands)
  17.    0    == when the procedure does nothing (SRE will then take care of the response)
  18.  contents == the contents to be sent to the client.  
  19.              
  20. A special variant of "contents" should be used if you've modified the mime=type:
  21.     modstring||' '||mime/sub||'0d0a'x||contents
  22. where "mime/sub" is the new mimetype.
  23. An even more advanced form of "contents" is:
  24.     modstring||' '||mime/sub||' 1 '||'0d0a'x||contents
  25. which will also "suppress delta encoding".
  26.  
  27. Note that the "sref_prereply_proc" procedure name is an arbitrary name
  28. used by sre-http when saving this procedure file to macrospace; you do NOT 
  29. have to use this as a label anywhere in your procedure.
  30.  
  31.  
  32. Info on this example:
  33.  
  34. This procedure will label the origin of this contents:
  35.   text/plain -- a line is added at the top
  36.   text/html  -- an html comment is added at the top
  37.   image/gif -- a gif comment is added at the end
  38. otherwise
  39.   a x-sre_message response header is added
  40.  
  41. Note:the use of  pre_reply procedures require sre-http ver 1.3c and above.
  42.  
  43. */
  44.  
  45. sref_prereply_proc:
  46. parse arg contents,fileflag,mimetype,clen,modstring
  47.  
  48. if fileflag=1 then 
  49.    jlen=stream(contents,'c','query size')
  50. else
  51.    jlen=length(contents)
  52.  
  53. call pmprintf('SRE-http pre-reply: 'fileflag' content-length = 'clen '('jlen ') and content-type= ' mimetype)
  54.  
  55. addaa='Produced on '||time('n')' 'date('n')', from '||servername()||'0d0a'x
  56.  
  57. select
  58.   when translate(mimetype)='TEXT/PLAIN' then do
  59.      addaa='From 'servername()||' on  '||time('n')' 'date('n')||'0d0a'x||'0d0a'x
  60.      if fileflag=1 then do
  61.        foo=stream(contents,'c','open read')
  62.        aa=charin(contents,1,jlen)
  63.        foo=stream(contents,'c','close')
  64.        aa=addaa||aa
  65.      end /* do */
  66.      else do
  67.       aa=addaa||contents
  68.      end
  69.      newlen=length(aa)
  70.      return aa
  71.    end
  72.   when translate(mimetype)='TEXT/HTML' then do
  73.      addaa='<!-- From 'servername()||' on  '||time('n')' 'date('n')||'-->'||'0d0a'x
  74.  
  75.      if fileflag=1 then do
  76.        foo=stream(contents,'c','open read')
  77.        aa=charin(contents,1,jlen)
  78.        foo=stream(contents,'c','close')
  79.        aa=addaa||aa
  80.      end /* do */
  81.      else do
  82.       aa=addaa||contents
  83.      end
  84.      newlen=length(aa)
  85.      return aa
  86.    end
  87.  
  88.   when translate(mimetype)='IMAGE/GIF' then do
  89.      addaa=make_comment('From 'servername()||' on  '||time('n')' 'date('n'))
  90.  
  91.      if fileflag=1 then do
  92.        foo=stream(contents,'c','open read')
  93.        aa=charin(contents,1,jlen)
  94.        foo=stream(contents,'c','close')
  95.      end /* do */
  96.      else do
  97.       aa=contents
  98.      end
  99.      aa=left(aa,jlen-1)||addaa||'3b'x   
  100.      newlen=length(aa)
  101.      return aa
  102.    end
  103.  
  104.  
  105.   otherwise do
  106.        addaa='X-sre_message: From 'servername()||' on  '||time('n')' 'date('n')
  107.        'HEADER ADD 'addaa
  108.        return 0          /* let sre handle it (though this header will also be sent */
  109.   end 
  110. end
  111.  
  112.  
  113. /***********/
  114. make_comment:procedure
  115. parse arg acomment
  116. aa='21fe'x
  117. aa=aa||chunkit(acomment)
  118. return aa
  119.  
  120. /***********/
  121. /* make a chewable chunk of data */
  122. chunkit:procedure
  123. parse arg astr,klen
  124. if klen='' then klen=250
  125. mkit=''
  126. lenstr=length(astr)
  127. do mm=1 to lenstr by 250 
  128.    iget=min(250,1+lenstr-mm)
  129.    a1=substr(astr,mm,iget)
  130.    a0=d2c(iget)
  131.    mkit=mkit||a0||a1
  132. end
  133. mkit=mkit||'00'x   
  134. return mkit
  135.  
  136.