home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / urlchk02.zip / URLChecker.cmd < prev    next >
OS/2 REXX Batch file  |  1999-02-22  |  4KB  |  152 lines

  1. /* Rexx - URLChecker/0.0.2 */
  2.  
  3. /****************************************************************************/
  4. /* load the rexx socket functions from rxsock.dll (must be in libpath)      */
  5. /****************************************************************************/
  6. if RxFuncQuery('SockLoadFuncs') then
  7.   do
  8.    rc = RxFuncAdd('SockLoadFuncs','RxSock','SockLoadFuncs')
  9.    rc = SockLoadFuncs()
  10.   end
  11.  
  12. parse arg file
  13.  
  14. inifile='URLChecker.ini'
  15.  
  16. rc=stream(file,'c','open read')
  17. URL=linein(file)
  18. rc=stream(file,'c','close')
  19.  
  20. say 'Checking "' || URL || '" from "' || file ||'"...'
  21.  
  22. last_modified = SysINI(inifile,URL,'Last-Modified')
  23. if last_modified='ERROR:' then last_modified=''
  24.  
  25. info=retrieve(url,last_modified)
  26. /* say 'retrieve()='info */
  27.  
  28. parse value info with status data1
  29. /* say 'Status:' status
  30. say 'Data1:' data1 */
  31.  
  32. select
  33.  when status=200 then
  34.   do
  35.     say 'Document was modified...'
  36.     rc=SysSetIcon(file,'MODIFIED.ICO')
  37.     say ' Old Last-Modified:' last_modified
  38.     say ' New Last-Modified:' data1
  39.     rc=SysINI(inifile,URL,'Last-Modified',data1)
  40.   end
  41.  when status=304 then rc=SysSetIcon(file,'NOTMODIFIED.ICO')
  42.  when status=0 then rc=SysSetIcon(file,'NOCONNECT.ICO')
  43.  when status=404 then rc=SysSetIcon(file,'NOTFOUND.ICO')
  44.  otherwise NOP
  45. end
  46.  
  47. return 0
  48.  
  49. retrieve: procedure
  50.  parse arg url,last_modified
  51.  
  52. crlf='0D0A'x
  53. use_proxy=0
  54. proxy_ip=''
  55. proxy_port=''
  56. parse value url with 'http://'hostname'/'path
  57. if use_proxy=0 then parse value hostname with hostname':'port
  58.  else
  59.   do
  60.    hostname=proxy_ip
  61.    port=proxy_port
  62.   end
  63.  
  64. if use_proxy=0 then
  65.  do
  66.   httpheader='GET /'path 'HTTP/1.0'crlf'User-Agent: URLChecker/0.0.2 (OS/2; M.Haller)'crlf'If-Modified-Since:'last_modified || crlf || crlf
  67.  end
  68. else
  69.  do
  70.   httpheader='GET' url 'HTTP/1.0'crlf'Host:'hostname||crlf'User-Agent: URLChecker/0.0.2 (OS/2; M.Haller)'crlf'If-Modified-Since:'last_modified || crlf || crlf
  71.  end
  72.   
  73.   if port='' then port=80
  74.   
  75. /* say 'Hostname='hostname 'Port='port 'Path='path 'URL='url
  76. say 'HTTPHeader: ['httpheader']' */
  77.  
  78. parse value hostname with ip1'.'ip2'.'ip3'.'ip4
  79. if datatype(ip1,'NUM')&datatype(ip2,'NUM')&datatype(ip3,'NUM')&datatype(ip4,'NUM') then
  80.  do
  81.   ip_address = hostname
  82.  end
  83. else
  84.  do
  85.   rc = SockGetHostByName(hostname,'host.')
  86.   if rc = '0' then return '0'
  87.   ip_address = host.addr
  88.  end
  89.  
  90. select
  91.  when use_proxy = 1 then /* use the proxy */
  92.   do
  93.    http_server.family = 'AF_INET'
  94.    http_server.port   = proxy_port
  95.    http_server.addr   = proxy_ip
  96.   end
  97.  otherwise /* do not use the proxy */
  98.   do
  99.    http_server.family = 'AF_INET'
  100.    http_server.port   = port
  101.    http_server.addr   = ip_address
  102.   end
  103. end
  104.  
  105. /****************************************************************************/
  106. /* open a socket                                                            */
  107. /****************************************************************************/
  108. socket = SockSocket('AF_INET','SOCK_STREAM',0)
  109. if socket = '-1' then return '0'
  110.  
  111. /****************************************************************************/
  112. /* connect to the server, if unsuccessfull exit with 0                      */
  113. /****************************************************************************/
  114. /*   say 'Connecte zu' http_server.addr 'auf Port' http_server.port 'auf Socket' socket */
  115.   rc = SockConnect(socket,'http_server.')
  116. if rc = '-1' then return '0'
  117.  
  118. rc = SockSend(socket,httpheader)
  119.  
  120. data = ''
  121. do while rc > 0
  122.   rc = SockRecv(socket,'newData',2048)
  123.   if rc = '-1' then return '0'
  124.   data = data || newData
  125. end
  126.  
  127. rc = SockSoClose(socket)
  128. if rc = '-1' then return '0'
  129.  
  130. parse var data with status .
  131.  
  132.   statusdata=GetHTTPParm(data,'Last-Modified')
  133.   if statusdata='' then statusdata=GetHTTPParm(data,'Last-modified')
  134.  
  135. return status statusdata
  136.  
  137. GetHTTPParm:
  138.   parse arg Text,Tag
  139.   TagPosition = pos(translate(Tag),translate(Text))
  140.   Wert = ''
  141.   if TagPosition>0 then
  142.     do
  143.      TagLength=length(Tag)
  144.      ParmPos=TagPosition+TagLength+2  /* 2=  ": " */
  145.      LinefeedPos=pos(crlf,Text,ParmPos)
  146.      if LinefeedPos=0 then LinefeedPos=pos(d2c(13),Text,ParmPos)
  147.      if LinefeedPos=0 then LinefeedPos=pos(d2c(10),Text,ParmPos)
  148.      ParmLength=LinefeedPos - Parmpos
  149.      if (ParmPos>0) & (ParmLength>0) then Wert=substr(Text,ParmPos,ParmLength)
  150.     end
  151. return Wert
  152.