File scpm-md5.patch of Package scpm
--- scpm-1.1.7.orig/src/main/modlib.cc
+++ scpm-1.1.7/src/main/modlib.cc
@@ -21,79 +21,44 @@
#include <cstdlib>
#include <cstdio>
#include <string>
-#include <mhash.h>
#include <fcntl.h>
#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
+#include <cryptopp/md5.h>
+#include <cryptopp/files.h>
+#include <cryptopp/filters.h>
+#include <cryptopp/hex.h>
+
using namespace std;
+using namespace CryptoPP::Weak1;
+using namespace CryptoPP;
#define module_name "modlib"
string Modlib::GetMD5sum( string filename )
{
- int c;
- int fd;
- MHASH td;
- unsigned char buffer[4096];
- unsigned char *hash;
- static char hash_string[33];
- string hash_s;
-
- td = mhash_init(MHASH_MD5);
-
- if (td == MHASH_FAILED) return("__unknown");
-
- if ( (fd=open( filename.c_str(), O_RDONLY )) == -1 ) {
- return("__unknown");
- }
-
- while ( (c=read(fd, &buffer, 4096)) >0) {
- mhash(td, &buffer, c);
- }
-
- hash = (unsigned char *) mhash_end(td);
-
- for ( unsigned int i = 0; i < mhash_get_block_size(MHASH_MD5); i++) {
- sprintf(&hash_string[i*2], "%.2x", hash[i]);
- }
-
- close(fd);
- hash_s = hash_string;
+ MD5 hash;
+ byte buffer[2 * MD5::DIGESTSIZE];
+
+ FileSource f(filename.c_str(), true,
+ new HashFilter(hash,
+ new HexEncoder(new ArraySink(buffer,2 * MD5::DIGESTSIZE), false)));
- return hash_s;
+ return string((const char*)buffer,2 * MD5::DIGESTSIZE);
}
string Modlib::GetMD5sum( istream &input )
{
- int c;
- MHASH td;
- unsigned char buffer[4096];
- unsigned char *hash;
- static char hash_string[33];
- string hash_s;
-
- td = mhash_init(MHASH_MD5);
-
- if (td == MHASH_FAILED) return("__unknown");
-
- while ( input.get( (char*)buffer, 4096, '\0' ) ) {
- c = input.gcount();
- mhash(td, &buffer, c);
- }
-
- hash = (unsigned char *) mhash_end(td);
-
- for ( unsigned int i = 0; i < mhash_get_block_size(MHASH_MD5); i++) {
- sprintf(&hash_string[i*2], "%.2x", hash[i]);
- }
-
+ MD5 hash;
+ byte buffer[2 * MD5::DIGESTSIZE];
+ FileSource f(input, true, new HashFilter(hash, new HexEncoder(new ArraySink(buffer,2 * MD5::DIGESTSIZE), false)));
+ return string((const char*)buffer,2 * MD5::DIGESTSIZE);
- hash_s = hash_string;
- return hash_s;
}
int Modlib::CallHandler( string resource_type, string resource_name,
--- scpm-1.1.7.orig/src/libscpm/Makefile
+++ scpm-1.1.7/src/libscpm/Makefile
@@ -8,7 +8,7 @@ libscpm-schemes.so: libscpm-schemes.c
gcc -g -o libscpm-schemes.so -I../../include -shared libscpm-schemes.c
libscpm.so.$(LIBVERSION): ../main ../modules ../scdb
- g++ -shared -fPIC -o libscpm.so.$(LIBVERSION) -Xlinker --whole-archive ../main/libmain.a ../modules/libmodules.a ../scdb/libscdb.a -Xlinker -lmhash -Xlinker -call_shared -Xlinker --no-whole-archive -Wl,-soname,libscpm.so.$(APIVERSION)
+ g++ $(CXXFLAGS) -shared -fPIC -o libscpm.so.$(LIBVERSION) -Xlinker --whole-archive ../main/libmain.a ../modules/libmodules.a ../scdb/libscdb.a -Xlinker -lcryptopp -Xlinker -call_shared -Xlinker --no-whole-archive -Wl,-soname,libscpm.so.$(APIVERSION)
ln -sf libscpm.so.$(LIBVERSION) libscpm.so
clean:
rm -f libscpm.so.$(LIBVERSION) libscpm.o libscpm++.so libscpm-schemes.so libscpm.so