home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / imagemap.zip / ImageMap.80 < prev    next >
Text File  |  1994-07-22  |  8KB  |  239 lines

  1. /*     ImageMap.cmd      version 1.00        */
  2. /* REXX routine to handle WWW Imagemap processing under the OS/2 gopher server. */
  3.  
  4. /* Created by D.L. Meyer;  22 July, 1994 */
  5.  
  6. /*  To Install: copy this file into your GoServe directory, naming it 'ImageMap.##'  */
  7. /*    where ## is the TCP/IP port number the server is operating on.  */
  8. /*        (Should be the same as GoFilter.##.)        */
  9.  
  10.  
  11.     /*  Initialize variables  */
  12. ImageMapVersion '1.00'
  13. mapConf = 'conf\imagemap.cnf'
  14. Default = ''
  15. ServerAdmin = '[The Server Administrator]'
  16. TestMode = 0
  17. MapID = 0
  18.  
  19.     /*  Parse command arguments into variables to use here. */
  20. Parse arg outfile, Parms, MapName, pathparms
  21. Parse var Parms iX ',' iY
  22.  
  23.     /* Link to the external function(s) we need */
  24. Call RxFuncAdd 'SysFileDelete', 'RexxUtil', 'SysFileDelete'
  25. call SysFileDelete outfile
  26.  
  27.     /* Begin the Main process: */
  28.  
  29.     /* Read the Map List into a stem variable. */
  30. i = 0
  31. Text = '%'
  32. do while (Text \= '')
  33.   i = i + 1
  34.   Text = linein(mapConf)
  35.   parse var Text N ' : ' Map.filename.i
  36.   parse upper var N Map.name.i
  37. end
  38.  
  39.     /* Set 'NumMaps' to the number of maps located.  */
  40. NumMaps = i - 1
  41.  
  42.     /* Set MapID to index of the first matching defined MapName; to 0 if no match */
  43. i = 1
  44. do while ((i <= NumMaps) & (MapName \= Map.name.i))
  45.   i = i + 1
  46. end
  47. if (i > NumMaps) then MapID = 0
  48. else MapID = i
  49.   
  50.     /* If a valid Map, then process the passed parameters & determine URL to return. */
  51. if  (MapID > 0) then
  52.   do 1
  53.     i = ReadMap(MapID)
  54.     _URL = GetURLfromMap( iX iY)
  55.   end
  56. else _URL = Default
  57.  
  58. Select
  59.     /* If a URL is available, and TESTMODE is not on, then redirect client */
  60.   When ((_URL \= '') & (TestMode == 0)) then 
  61.     do
  62.       call lineout outfile, "HTTP/1.0 302 Found"
  63.       call lineout outfile, 'Location: '_URL
  64.       call lineout outfile, ""
  65.     end
  66.     /* MapID = -1 shouldn't happen; reserved for later use..  */
  67.     /* 400 Bad Request forces client to report error - no HTML is displayed on client.  */
  68.   When (MapID = -1) then 
  69.     do
  70.       call lineout outfile, "HTTP/1.0 400 Bad Request"
  71.       call lineout outfile, ""
  72.     end
  73.     /* Undefined MapName -- send appropriate Error HTML... */
  74.   When (MapID = 0) then 
  75.     do
  76.       call lineout outfile, "<head><title>REXX Script Processor Output</title></head><body>"
  77.       call lineout outfile, "<h1>ERROR: Undefined Map</h1>"
  78.       call lineout outfile, "<hr>MapName=["Mapname"]<br>"
  79.       call lineout outfile, 'MapID='MapID'<hr>'
  80.       call lineout outfile, "Click Coordinates:<pre>   X=["iX"]<br>   Y=["iY"]<br><pre>"
  81.       call lineout outfile, '<hr><address>To define a new map, you must place your <em>'MapName'.MAP</em> '
  82.       call lineout outfile, 'file onto the server, and send email to 'ServerAdmin' requesting that your map'
  83.       call lineout outfile, ' be added to the configuration file.  [Your email message should tell of the mapname: "<em>'MapName'</em>" and the location of the <em>'MapName'.MAP</em> file.]</address>'
  84.       call lineout outfile, '<hr><address>Please report server-related problems to 'ServerAdmin'</address>'
  85.       call lineout outfile, "</body>"
  86.     end
  87.     /* Must have fallen through because of no 'Default' defined in .MAP file, */
  88.     /*  or TESTMODE is on.  Send debugging info via HTML.*/
  89.   Otherwise
  90.     do
  91.       call lineout outfile, "<head><title>REXX Script Processor Output</title></head><body>"
  92.       call lineout outfile, "<h1>ImageMap Input</h1>"
  93.  
  94.       call lineout outfile, "<hr>MapName=["Mapname"]<br>"
  95.       call lineout outfile, 'MapID='MapID'<hr>'
  96.       call lineout outfile, "Click Coordinates:<pre>   X=["iX"]<br>   Y=["iY"]<br><pre>"
  97.       call lineout outfile, 'TestMode='TestMode
  98.       call lineout outfile, 'NRegions='Region.NRegions
  99.       call lineout outfile, '<hr>Default = "'_URL'" <br>'
  100.       call lineout outfile, 'Redirect to URL = "'_URL'"<hr>'
  101.  
  102.       call lineout outfile, "</body>"
  103.     end
  104.   End   /* Select */
  105.  
  106. call lineout outfile    /* Close the output file */
  107. return MapName
  108.  
  109.     /* Read in the .MAP file into a stem variable.  [Region]  */
  110. ReadMap: procedure expose Region. Default Map. TestMode
  111.    parse arg ID        /* parse out passed variable. (represents MapID) */
  112.  
  113.     /* Initilizations */
  114.    i = 0
  115.    nR = 0
  116.    Text = '%'
  117.    Default = ''
  118.    TestMode = 0
  119.  
  120.     /* read in the region definitions from the .MAP file.  */
  121.    do while (Text \= '')
  122.      i = i + 1
  123.      Text = linein(Map.filename.ID)
  124.      parse var Text T  Region.URL.i  C1 C2
  125.      parse upper var T Region.Type.i
  126.  
  127.      Select
  128.  
  129.     /* If the TESTMODE keyword is present, set TestMode to on.  */
  130.        When (Region.Type.i = 'TESTMODE') then
  131.         do
  132.           i = i - 1
  133.           TestMode = 1
  134.         end
  135.  
  136.     /* DEFAULT keyword sets the default URL to redirect to in case of no region matches. */
  137.        When (Region.Type.i = 'DEFAULT') then
  138.          do 
  139.            Default = Region.URL.i
  140.            i = i - 1
  141.          end
  142.  
  143.     /* Parse out coordinates for the Rectangular region.  */
  144.        When (Region.Type.i = 'RECT') then
  145.          do 
  146.            parse var C1 Region.X1.i ',' Region.Y1.i
  147.            parse var C2 Region.X2.i ',' Region.Y2.i
  148.            nR = nR + 1
  149.  
  150.     /* ensure that X1,Y1 is upper left, and X2,Y2 is lower right... */
  151.            if (Region.X2.i < Region.X1.i) then     /* Swap... */
  152.             do 1
  153.               a = Region.X2.i
  154.               Region.X2.i = Region.X1.i
  155.               Region.X1.i = a
  156.             end
  157.            if (Region.Y2.i < Region.Y1.i) then     /* Swap... */
  158.             do 1
  159.               a = Region.Y2.i
  160.               Region.Y2.i = Region.Y1.i
  161.               Region.Y1.i = a
  162.             end
  163.          end
  164.  
  165.     /* Parse out coordinates for the Circle region.  */
  166.        When (Region.Type.i = 'CIRC') then
  167.          do 
  168.            parse var C1 Region.X1.i ',' Region.Y1.i
  169.         /* radius... */
  170.            Region.X2.i = C2
  171.            nR = nR + 1
  172.          end
  173.  
  174.     /* handle the standard blank line between 'Default' line and other regions... */
  175.        When (Region.Type.i = '') then
  176.          do 
  177.            if ((i = 1) & (Default \= '')) then 
  178.             do
  179.               Text = '%'
  180.               i = i - 1
  181.             end
  182.          end
  183.  
  184.     /* Must be an unknown region type... */
  185.        Otherwise
  186.          do 
  187.            say 'Unknown RegionType=['Region.Type.i']  URL=<'Region.URL.i'>  [C1='C1'  C2='C2']'
  188.            i = i - 1
  189.          end
  190.      End /* Select */     
  191.    end
  192.    Region.NRegions = nR
  193.    return nR
  194.  
  195. GetURLfromMap: procedure expose Region. Default Map.
  196.  
  197.     /* Parse out mouse click coordinates */
  198.    parse arg tX tY
  199.    i = 1
  200.    Hit = 0
  201.  
  202.     /* Set URL to the default, in case no regions are hit... */
  203.    _URL = Default
  204.  
  205.     /* Loop through the defined regions to find first hit. */
  206.    do while ((i <= Region.NRegions) & (Hit = 0))
  207.      Select
  208.  
  209.     /* Determine if coordinates lie within the rectangular area.  */
  210.        When Region.Type.i = 'RECT' then
  211.         do
  212.           Hit = ((tX >= Region.X1.i) & (tY >= Region.Y1.i) & (tX <= Region.X2.i) & (tY <= Region.Y2.i))
  213.         end
  214.  
  215.     /* Calc distance to coordinates from Circle center, and compare to radius.*/
  216.     /*   If less than radius, then it's a hit... */
  217.        When Region.Type.i = 'CIRC' then
  218.         do
  219.           a = tX - Region.X1.i
  220.           b = tY - Region.Y1.i
  221.           R = (a * a) + (b * b)
  222.           Hit = (R <= (Region.X2.i * Region.X2.i))
  223.         end
  224.  
  225.     /* The required 'Otherwise'... */
  226.        Otherwise
  227.         do
  228.         end
  229.      End /* Select */
  230.  
  231.     /* If a hit, then set '_URL' to stem URL value.  */
  232.      if (Hit = 1) then
  233.       do
  234.         _URL = Region.URL.i
  235.       end
  236.      i = i + 1
  237.    end
  238.    return _URL        /* return the identified URL */
  239.