/****************************** Module Header ******************************* * * Module Name: md5.e * * E wrapper routine to access the NEPMD library DLL. * Include of nepmdlib.e. * * Copyright (c) netlabs.org EPM Distribution Project 2022 * * $Id$ * * =========================================================================== * * This file is part of the netlabs.org EPM Distribution package and is free * software. You can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, * in version 2 as it comes in the "netlabs\help\COPYING" file of the * netlabs.org EPM Distribution. This library is distributed in the hope that * it will be useful, but WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * ****************************************************************************/ /* @@NepmdMd5@PROTOTYPE Md5Sum = NepmdMd5( Filename) @@NepmdMd5@CATEGORY@CHECKSUM @@NepmdMd5@SYNTAX This function calculates a MD5 checksum for a given file. It uses the *RSA Data Security, Inc. MD5 Message-Digest Algorithm*. @@NepmdMd5@PARM@Filename This parameter specifies the filename of the read file. @@NepmdMd5@RETURNS *NepmdMd5* returns the calculated MD5 checksum. In case of an error an empty string is returned. This procedure sets the implicit universal var *rc*. rc is set to an [inf:cp2 "Errors" OS/2 error code] or to zero for no error. @@NepmdMd5@TESTCASE You can test this function from the *EPM* commandline by executing: .sl - *NepmdMd5* [.IDPNL_EFUNC_NepmdMd5_PARM_Filename Filename] - or - *Md5* [.IDPNL_EFUNC_NepmdMd5_PARM_Filename Filename] Executing this command will open up a virtual file and display the MD5 checksum of the file with the specified filename. *Example:* .fo text Md5 c:\config.sys .fo on @@ */ ; --------------------------------------------------------------------------- ; Allow editor command to call function ; --------------------------------------------------------------------------- compile if NEPMD_LIB_TEST defc NepmdMd5, Md5 do i = 1 to 1 parse arg Args Args = strip( Args) if leftstr( Args, 1) = '"' then parse value Args with '"'Filename'"' else parse value Args with Filename endif Filename = strip( Filename) if (Filename = '') then sayerror 'Error: no filename specified.' leave endif Md5Sum = NepmdMd5( Filename) if rc then sayerror 'Error from NepmdMd5, rc = 'rc'.' leave endif HelperNepmdCreateDumpfile( 'NepmdMd5', Args) insertline 'The calculated MD5 checksum of 'Filename' is:' insertline Md5Sum .modify = 0 enddo compile endif ; --------------------------------------------------------------------------- ; Procedure: NepmdMd5 ; --------------------------------------------------------------------------- ; E syntax: ; Md5Sum = NepmdMd5( Filename) ; --------------------------------------------------------------------------- ; C prototype: ; APIRET NepmdMd5( PSZ pszFilename, ; PSZ pszBuffer, ; ULONG ulBuffLen); ; --------------------------------------------------------------------------- defproc NepmdMd5( Filename) BuffLen = 32 + 1 Md5Sum = copies( \0, BuffLen) -- Prepare parameter for C routine FilenameZ = Filename\0 -- Call C routine LibFile = HelperNepmdGetLibFile() rc = dynalink32( LibFile, "NepmdMd5", address( FilenameZ) || address( Md5Sum) || atol( BuffLen)) HelperNepmdCheckLibError( LibFile, rc) if rc then return else return MakeRexxString( Md5Sum) endif