home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / ppwizard.zip / valrurl.h < prev   
Text File  |  1999-11-20  |  18KB  |  369 lines

  1. ;----------------------------------------------------------------------------
  2. ;     MODULE NAME:   VALRURL.IH
  3. ;
  4. ;         $Author:   Dennis_Bareis  $
  5. ;       $Revision:   1.7  $
  6. ;           $Date:   20 Nov 1999 08:12:12  $
  7. ;        $Logfile:   E:/DB/PVCS.IT/OS2/PPWIZARD/VALRURL.H_V  $
  8. ;
  9. ;     DESCRIPTION:   This is a header file for checking HTTP/FTP urls on
  10. ;                    remote servers. All URLs are passed with a leading
  11. ;                    "http://' or "ftp://".
  12. ;
  13. ;                    This routine does not validate that any "#Section"
  14. ;                    on http URLs are correct. It will validate that the
  15. ;                    html page exists on the server.
  16. ;
  17. ;                    It will only check a URL once. This is the case even
  18. ;                    across builds of multiple ".IT" files if they are being
  19. ;                    built using the one call to PPWIZARD.
  20. ;
  21. ;                    Note that I don't search a table to work out if a URL
  22. ;                    has already been used, my method is much faster however
  23. ;                    on very long URLs which appear in multiple files in the
  24. ;                    same PPWIZARD invokation it may repeat the test.
  25. ;
  26. ;
  27. ;                    OPERATING SYSTEMS
  28. ;                    ~~~~~~~~~~~~~~~~~
  29. ;                    This header has only been tested under OS/2. The
  30. ;                    required DLLs appear to have been installed by OS/2
  31. ;                    version 4 (Merlin). If these are unavailable on your
  32. ;                    machine you may need a TCP-IP fixpack, otherwise you
  33. ;                    will need to locate a web page containing the files.
  34. ;
  35. ;                    Since there is a "RxSock.DLL" available for windows
  36. ;                    http checking will also work there (if any changes
  37. ;                    required please let me know the details).
  38. ;                    There is no "RxFtp.DLL" for windows (that I know of).
  39. ;
  40. ;                    You can get RxSock for windows from:
  41. ;
  42. ;                                http://home.hiwaay.net/~abbott/regina/
  43. ;
  44. ;
  45. ;                    COMMENTS
  46. ;                    ~~~~~~~~
  47. ;                    Error messages could be improved a bit!
  48. ;
  49. ;                    Not sure about all error handling, please let me know
  50. ;                    of any issues you have. If you can see that I'm doing
  51. ;                    something wrong, please tell me!
  52. ;
  53. ;
  54. ;                    EXAMPLE
  55. ;                    ~~~~~~~
  56. ;                    ;;#define  VALRURL_NO_CHECK_HTTP
  57. ;                    ;;#define  VALRURL_NO_CHECK_FTP
  58. ;                    ;;#define  VALRURL_DEBUG            out\DEBUG.URL\*.DBG
  59. ;                    #define    VALRURL_CHECK_LATER_MASK out\REMOTE.URL\*.URL
  60. ;                    #define    VALRURL_FTP_EMAIL        db0@anz.com
  61. ;                    #include "VALRURL.H"
  62. ;
  63. ;                    <P>Please see
  64. ;                    <A HREF="<$RemHttp url="http://www.labyrinth.net.au/~dbareis/ppwizard.htm">">
  65. ;                       PPWIZARD's homepage
  66. ;                    </A>.
  67. ;
  68. ;                    You may wish to come up with your own set of "front end"
  69. ;                    macros to simplify the above. Also in general I recommend
  70. ;                    defining the external URL's in a header if they are to
  71. ;                    be used in more than one place.
  72. ;----------------------------------------------------------------------------
  73.  
  74.  
  75. ;--- Initialization (for this compile) --------------------------------------
  76. #ifdef  VALRURL_CHECK_LATER_MASK
  77.         #DefineRexx ''
  78.            ;--- Create URL file name based on input name ---
  79.            UrlListFile = GenerateFileName('<?InputFile>', '<$VALRURL_CHECK_LATER_MASK>');
  80.  
  81.            ;--- Delete the file for starters, will get created if any URLs ---
  82.            call stream UrlListFile, 'c', 'close';
  83.            call _SysFileDelete UrlListFile;
  84.         #DefineRexx
  85. #endif
  86.  
  87.  
  88. ;--- Only do rest of header once! -------------------------------------------
  89. #ifndef VERSION_VALRURL_IH
  90.    ;--- Define the version number of this header file -----------------------
  91.    #define   VERSION_VALRURL_IH    99.315
  92.    #require  99.315
  93.  
  94.    ;--- Need access to sort stuff ------------------------------------------
  95.    #include "PPWSORT.H"
  96.  
  97.    ;--- Allow user to prevent generation if they only wish validation ------
  98.    #ifndef RemHttpGenerate
  99.        #define RemHttpGenerate      {$URL}
  100.    #endif
  101.    #ifndef RemFtpGenerate
  102.        #define RemFtpGenerate       {$URL}
  103.    #endif
  104.  
  105.    ;--- Allow user to modify what happens on failing validation ------------
  106.    #ifndef VALRURL_FAILED_VALIDATION_REXX
  107.            #DefineRexx VALRURL_FAILED_VALIDATION_REXX
  108.                    call warning "CRURL", ThisUrl || ' ==> ' || UrlChkRc;
  109.            #DefineRexx
  110.    #endif
  111.  
  112.    ;--- Allow user to modify what happens on successful validation ---------
  113.    #ifndef VALRURL_VALIDATED_OK_REXX
  114.            ;--- Default is display success only when debug is on -----------
  115.            #ifdef  VALRURL_DEBUG
  116.                    ;--- Display successful URL as debug is on --------------
  117.                    #DefineRexx VALRURL_VALIDATED_OK_REXX
  118.                                call info 'DEBUG: ' || ThisUrl || ' successfully validated';
  119.                    #DefineRexx
  120.            #elseif
  121.                    ;--- Define empty handler if debug is off ---------------
  122.                    #define VALRURL_VALIDATED_OK_REXX
  123.            #endif
  124.    #endif
  125.  
  126.  
  127.    ;--- Allow user to specify email address for FTP site logon -------------
  128.    #ifndef VALRURL_FTP_EMAIL
  129.            #define VALRURL_FTP_EMAIL VALRURL_<$VERSION_VALRURL_IH>@real.email.address.unknown
  130.    #endif
  131.  
  132.    ;--- User calls these macros to perform validation ----------------------
  133.    #define RemHttp                                                  \
  134.            <$ValidateHttpR    URL="{$URL}">     ;;Check Remote URL -\
  135.            <$RemHttpGenerate  URL="{$URL}">     ;;Generate URL
  136.    #define RemFtp                                                   \
  137.            <$ValidateFtpR     URL="{$URL}">     ;;Check Remote URL -\
  138.            <$RemHttpGenerate  URL="{$URL}">     ;;Generate URL
  139.  
  140.    ;--- Checking HTTP:// ? -------------------------------------------------
  141.    #ifdef  VALRURL_NO_CHECK_HTTP
  142.            #define ValidateHttpR   ;;No checking
  143.    #elseif
  144.            #define ValidateHttpR   <$ValidateUrlR Type="http://" URL="{$URL}">
  145.    #endif
  146.  
  147.  
  148.    ;--- Checking FTP:// ? --------------------------------------------------
  149.    #ifdef  VALRURL_NO_CHECK_FTP
  150.            #define ValidateFtpR    ;;No checking
  151.    #elseif
  152.            #define ValidateFtpR    <$ValidateUrlR Type="ftp://" URL="{$URL}">
  153.    #endif
  154.  
  155.    ;--- Initialization - Once per PPWIZARD Invokation (NOT build!) ---------
  156.    #if symbol('UrlCheckerPgm') <> 'VAR'
  157.        ;--- No need to do anything if delaying the checking! ---------------
  158.        #ifndef VALRURL_CHECK_LATER_MASK
  159.            #if Defined('VALRURL_NO_CHECK_HTTP') = 'N' | Defined('VALRURL_NO_CHECK_FTP') = 'N'
  160.                ;--- Find External program ----------------------------------
  161.                #define VALRURL_EXT_CMD   PPWCURL.CMD
  162.                #evaluate ''                                                                                           \
  163.                ^                                                                                                      \
  164.                    UrlCheckerPgm = _SysSearchPath('PATH', '<$VALRURL_EXT_CMD>');                                      \
  165.                    if  UrlCheckerPgm = '' then;                                                                       \
  166.                    do;                                                                                                \
  167.                        parse source . . PpwRexxFile;                                                                  \
  168.                        UrlCheckerPgm = _filespec('location', PpwRexxFile) || '<$VALRURL_EXT_CMD>';                    \
  169.                            if  stream(UrlCheckerPgm, 'c', 'query exists') = '' then;                                  \
  170.                                Error('Could not locate "<$VALRURL_EXT_CMD>" (searched PATH and PPWIZARD directory)'); \
  171.                    end;                                                                                               \
  172.                ^
  173.  
  174.                ;--- Display version numbers of DLLs we are using -----------
  175.                #evaluate '' ^interpret 'ExtCmdVersion = "<??UrlCheckerPgm>"("VERSION?")'^
  176.                #info        'Header file version <$VERSION_VALRURL_IH>'
  177.                #info        'Using Check URL external command <??ExtCmdVersion>'
  178.                #ifndef  VALRURL_NO_CHECK_HTTP
  179.                    #evaluate '' ^interpret 'SocketVersion = "<??UrlCheckerPgm>"("SOCKETVERSION?")'^
  180.                    #info     'Validating remote http URLs with <??SocketVersion>'
  181.                #endif
  182.                #ifndef  VALRURL_NO_CHECK_FTP
  183.                    #evaluate '' ^interpret 'FtpVersion    = "<??UrlCheckerPgm>"("FTPVERSION?")'^
  184.                    #info     'Validating remote ftp  URLs with <??FtpVersion>'
  185.                #endif
  186.  
  187.                ;--- Set email address for FTP downloads --------------------
  188.                #ifndef  VALRURL_NO_CHECK_FTP
  189.                    #evaluate '' ^call SetEnv "PPWCURL_EMAIL", "<$VALRURL_FTP_EMAIL>"^
  190.                #endif
  191.            #endif
  192.        #endif
  193.    #endif
  194.  
  195.    ;--- Set up debug? ----------------------------------------------
  196.    #ifndef  VALRURL_DEBUG
  197.        #evaluate '' ^call SetEnv "PPWCURL_DEBUG", ''^            ;;Prevent Debug
  198.    #elseif
  199.        #evaluate '' ^TDbgFile = GenerateFileName('<?InputFile>', '<$VALRURL_DEBUG>')^
  200.        #evaluate '' ^call _SysFileDelete TDbgFile^
  201.        #evaluate '' ^call SetEnv "PPWCURL_DEBUG", TDbgFile^      ;;Turn it on
  202.        #info        'Any debugger output goes to "<??TDbgFile>"'
  203.    #endif
  204.  
  205.    ;--- Make sure we have required support for this compile -----------------
  206.    #ifndef VALRURL_CHECK_LATER_MASK
  207.        #ifndef  VALRURL_NO_CHECK_HTTP
  208.            #evaluate '' ^interpret 'SupportHttp = "<??UrlCheckerPgm>"("SOCKETREADY?")'^
  209.            #if SupportHttp <> 'OK'
  210.                ;--- Can't validate HTTP URLs -----------------------------------
  211.                #Warning "CRURL"  "Can't validate HTTP URLs"
  212.                #define+ RemHttp <$RemHttpGenerate  URL="{$URL}"> ;;Can't validate URL
  213.            #endif
  214.        #endif
  215.        #ifndef  VALRURL_NO_CHECK_FTP
  216.            #evaluate '' ^interpret 'SupportFtp  = "<??UrlCheckerPgm>"("FTPREADY?")'^
  217.            #if SupportFtp <> 'OK'
  218.                ;--- Can't validate FTP URLs -----------------------------------
  219.                #Warning "CRURL"  "Can't validate FTP URLs"
  220.                #define+ RemFtp <$RemFtpGenerate  URL="{$URL}">   ;;Can't validate URL
  221.            #endif
  222.        #endif
  223.    #endif
  224.  
  225.    ;--- Initialization for this build ---------------------------------------
  226.    #RexxVar ValUrlCount = 0            ;;Counts elements in URL array
  227.    #OnExit  <$ProcessRemoteUrlList>    ;;Handle the list (user could override macro)
  228.  
  229.    ;--- Handle URL (just add to array, don't worry about duplicates here) ---
  230.    #define ValidateUrlR                                                      \
  231.            ;--- Make sure we validate a full URL -------------              -\
  232.            #evaluate '' ^<$ValidateUrlR_REXX_FullUrl Type="{$Type}" URL="{$URL}">^  -\
  233.                                                                             -\
  234.            ;--- Add URL (in "FullUrl" var) to end of array ---              -\
  235.            #RexxVar ValUrlCount + 1                                         -\
  236.            #RexxVar ValUtlList.ValUrlCount = FullUrl                        -\
  237.                                                                             -\
  238.            ;--- Add location ---------------------------------              -\
  239.            #evaluate '' ^<$ValidateUrlR_REXX_Location>^                     -\
  240.            #RexxVar ValUtlLocn.ValUrlCount = UrlSourceLocation
  241.    #DefineRexx ValidateUrlR_REXX_FullUrl
  242.                ;--- Make sure URL starts with "http:" etc ---
  243.                UrlType = "{$Type}";
  244.                FullUrl = "{$URL}";
  245.                if  abbrev(FullUrl, UrlType) = 0 then;
  246.                    FullUrl = UrlType || FullUrl;
  247.  
  248.                ;--- Remove any "#section" bit ---
  249.                #Option PUSH AllowPack=NO
  250.                parse var FullUrl (UrlType) httpServer '/' HttpPageAddr;
  251.                #Option POP
  252.                parse var HttpPageAddr HttpPageAddr '#';
  253.                FullUrl = UrlType || httpServer || '/' || HttpPageAddr;
  254.    #DefineRexx
  255.    #ifndef ValidateUrlR_REXX_Location              ;;Allow caller to create their own "location"
  256.        #DefineRexx ValidateUrlR_REXX_Location
  257.                    #Option PUSH AllowPack=NO
  258.                    do  IncIndex = 1 to <?IncludeLevel>
  259.                    #Option POP
  260.                        ;--- Format the input file at this level ---
  261.                        ThisBit = _filespec('name', InputComponentLevel(IncIndex));
  262.                        ThisBit = ThisBit || '(' || AddCommasToDecimalNumber(InputComponentLineLevel(IncIndex)) || ')';
  263.  
  264.                        ;--- Update location string ----------------
  265.                        if  IncIndex = 1 then
  266.                            UrlSourceLocation = ThisBit;
  267.                        else
  268.                            UrlSourceLocation = UrlSourceLocation || '->' || ThisBit;
  269.                    end
  270.        #DefineRexx
  271.    #endif
  272.  
  273.    ;--- Work though URL list and end of successful build --------------------
  274.    #define ProcessRemoteUrlList                                \
  275.            #if [ValUrlCount = 0]                              -\
  276.                #info 'No remote URLs to validate'             -\
  277.            #elseif                                            -\
  278.                #info 'Validating <??ValUrlCount> remote URLs' -\
  279.                ;--- Sort the array ---                        -\
  280.                #RexxVar ValUtlList.0 = ValUrlCount            -\
  281.                #evaluate '' ^<$GenRexx2Sort2Arrays ARRAY1='ValUtlList' ARRAY2='ValUtlLocn'>^ -\
  282.                                                               -\
  283.                ;--- Process the array ---                     -\
  284.                #evaluate '' ^<$ProcessRemoteUrlList_REXX>^    -\
  285.            #endif
  286.    #DefineRexx ProcessRemoteUrlList_REXX_COMMON_START
  287.            ;--- Work through URL list (drop duplicates) ---
  288.            LastUrl = '';
  289.            LastLoc = '';
  290.            do  UrlIndex = 1 to ValUtlList.0
  291.                ThisUrl = ValUtlList.UrlIndex;
  292.                ThisLoc = ValUtlLocn.UrlIndex;
  293.                if  ThisUrl <> LastUrl | ThisLoc <> LastLoc then;
  294.                do
  295.    #DefineRexx
  296.    #DefineRexx ProcessRemoteUrlList_REXX_COMMON_END
  297.                    LastUrl = ThisUrl;
  298.                    LastLoc = ThisLoc;
  299.                end;
  300.            end;
  301.    #DefineRexx
  302.  
  303.    ;--- What are we doing with the list of URLs? ----------------------------
  304.    #ifndef ProcessRemoteUrlList_REXX
  305.        #ifdef  VALRURL_CHECK_LATER_MASK
  306.            ;--- Generate file (user will check URLs later / when online) ----
  307.            #DefineRexx ProcessRemoteUrlList_REXX
  308.                    ;--- We already know URL filename & its been deleted ---
  309.                    call Info 'Generating: ' || UrlListFile;
  310.                    call lineout UrlListFile, ';---';
  311.                    call lineout UrlListFile, ';--- Remote URLs from "<?InputFile>"';
  312.                    call lineout UrlListFile, ';--- Use PPWCURL.CMD under OS/2 or other similar';
  313.                    call lineout UrlListFile, ';--- tool to process the list.';
  314.                    call lineout UrlListFile, ';---';
  315.                    call lineout UrlListFile, '';
  316.                    call lineout UrlListFile, '';
  317.  
  318.                    ;--- Now work through the list of URLs ---
  319.                    <$ProcessRemoteUrlList_REXX_COMMON_START>;
  320.                        ;--- Need to output new location pragma? ---
  321.                        if  ThisLoc <> LastLoc then
  322.                            call lineout UrlListFile, ';PRAGMA(URL_SOURCE)=' || ThisLoc;
  323.  
  324.                        call lineout UrlListFile, ThisUrl;
  325.                    <$ProcessRemoteUrlList_REXX_COMMON_END>;
  326.  
  327.                    ;--- Close the listing file ---
  328.                    call DieIfIoErrorOccurred UrlListFile;
  329.                    CloseRc = stream(UrlListFile, 'c', 'close');
  330.            #DefineRexx
  331.        #elseif
  332.            ;--- We are online, do immediate check of URLs -------------------
  333.            #DefineRexx ProcessRemoteUrlList_REXX
  334.                    <$ProcessRemoteUrlList_REXX_COMMON_START>;
  335.                        ;--- Calculate ID for this URL ---
  336.                        FullPageId     = '!R_' || c2x(ThisUrl);
  337.                        FullPageIdStat = symbol(FullPageId);    ;;Exists/Name too long?
  338.  
  339.                        ;--- Already done this URL (previous build)? ---
  340.                        if  FullPageIdStat = 'VAR' then;
  341.                            UrlChkRc = _valueG(FullPageId);   ;;Already know if valid!
  342.                        else;
  343.                        do;
  344.                            ;--- Haven't checked yet ---
  345.                            interpret 'UrlChkRc = "<??UrlCheckerPgm>"("CHECK1URL " || ThisUrl)';
  346.  
  347.                            ;--- Set ID so we won't repeat this exercise! ---
  348.                            if  FullPageIdStat <> 'BAD' then;
  349.                                call _valueS FullPageId, UrlChkRc;
  350.                        end;
  351.  
  352.                        ;--- Handle return code ---
  353.                        if  UrlChkRc = 'OK' then;
  354.                        do;
  355.                            <$VALRURL_VALIDATED_OK_REXX>;
  356.                        end;
  357.                        else;
  358.                        do;
  359.                            <$VALRURL_FAILED_VALIDATION_REXX>;
  360.                        end;
  361.                    <$ProcessRemoteUrlList_REXX_COMMON_END>;
  362.            #DefineRexx
  363.        #endif
  364.    #endif
  365.  
  366. #endif
  367.  
  368.  
  369.