home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / srev13g.zip / prerep.cmd < prev    next >
OS/2 REXX Batch file  |  1999-04-27  |  4KB  |  133 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.  
  24. Note that the "sref_prereply_proc" procedure name is an arbitrary name
  25. used by sre-http when saving this procedure file to macrospace; you do NOT 
  26. have to use this as a label anywhere in your procedure.
  27.  
  28.  
  29. Info on this example:
  30.  
  31. This procedure will label the origin of this contents:
  32.   text/plain -- a line is added at the top
  33.   text/html  -- an html comment is added at the top
  34.   image/gif -- a gif comment is added at the end
  35. otherwise
  36.   a x-sre_message response header is added
  37.  
  38. Note:the use of  pre_reply procedures require sre-http ver 1.3c and above.
  39.  
  40. */
  41.  
  42. sref_prereply_proc:
  43. parse arg contents,fileflag,mimetype,clen,modstring
  44.  
  45. if fileflag=1 then 
  46.    jlen=stream(contents,'c','query size')
  47. else
  48.    jlen=length(contents)
  49.  
  50. call pmprintf('SRE-http pre-reply: 'fileflag' content-length = 'clen '('jlen ') and content-type= ' mimetype)
  51.  
  52. addaa='Produced on '||time('n')' 'date('n')', from '||servername()||'0d0a'x
  53.  
  54. select
  55.   when translate(mimetype)='TEXT/PLAIN' then do
  56.      addaa='From 'servername()||' on  '||time('n')' 'date('n')||'0d0a'x||'0d0a'x
  57.      if fileflag=1 then do
  58.        foo=stream(contents,'c','open read')
  59.        aa=charin(contents,1,jlen)
  60.        foo=stream(contents,'c','close')
  61.        aa=addaa||aa
  62.      end /* do */
  63.      else do
  64.       aa=addaa||contents
  65.      end
  66.      newlen=length(aa)
  67.      return aa
  68.    end
  69.   when translate(mimetype)='TEXT/HTML' then do
  70.      addaa='<!-- From 'servername()||' on  '||time('n')' 'date('n')||'-->'||'0d0a'x
  71.  
  72.      if fileflag=1 then do
  73.        foo=stream(contents,'c','open read')
  74.        aa=charin(contents,1,jlen)
  75.        foo=stream(contents,'c','close')
  76.        aa=addaa||aa
  77.      end /* do */
  78.      else do
  79.       aa=addaa||contents
  80.      end
  81.      newlen=length(aa)
  82.      return aa
  83.    end
  84.  
  85.   when translate(mimetype)='IMAGE/GIF' then do
  86.      addaa=make_comment('From 'servername()||' on  '||time('n')' 'date('n'))
  87.  
  88.      if fileflag=1 then do
  89.        foo=stream(contents,'c','open read')
  90.        aa=charin(contents,1,jlen)
  91.        foo=stream(contents,'c','close')
  92.      end /* do */
  93.      else do
  94.       aa=contents
  95.      end
  96.      aa=left(aa,jlen-1)||addaa||'3b'x   
  97.      newlen=length(aa)
  98.      return aa
  99.    end
  100.  
  101.  
  102.   otherwise do
  103.        addaa='X-sre_message: From 'servername()||' on  '||time('n')' 'date('n')
  104.        'HEADER ADD 'addaa
  105.        return 0          /* let sre handle it (though this header will also be sent */
  106.   end 
  107. end
  108.  
  109.  
  110. /***********/
  111. make_comment:procedure
  112. parse arg acomment
  113. aa='21fe'x
  114. aa=aa||chunkit(acomment)
  115. return aa
  116.  
  117. /***********/
  118. /* make a chewable chunk of data */
  119. chunkit:procedure
  120. parse arg astr,klen
  121. if klen='' then klen=250
  122. mkit=''
  123. lenstr=length(astr)
  124. do mm=1 to lenstr by 250 
  125.    iget=min(250,1+lenstr-mm)
  126.    a1=substr(astr,mm,iget)
  127.    a0=d2c(iget)
  128.    mkit=mkit||a0||a1
  129. end
  130. mkit=mkit||'00'x   
  131. return mkit
  132.  
  133.