Commit fceb5fb5 authored by Aleksey Kravchenko's avatar Aleksey Kravchenko

Imported Upstream version 1.2.9

parent 648a9ff8
Mon Apr 09 2011 Aleksey
* === Version 1.2.9 ===
Sun Apr 08 2012 Aleksey
* Bugfix: handling UNC filenames on Windows
* option --bt-batch for batch torrents
Sat Jan 7 2012 Aleksey
* librhash: rhash_print_magnet function
Sun Nov 06 2011 Sergey Basalaev
* .NET/Mono bindings to librhash
Wed Sep 14 2011 Aleksey
* === Version 1.2.8 ===
Wed Sep 14 2011 Aleksey, SBasalaev
* LibRHash bindings to Java, Perl, Python, Ruby
Tue Sep 6 2011 Aleksey
* librhash: implemented auto-final feature, turned on by default
......
......@@ -12,6 +12,9 @@ To test the compiled program run 'make test'.
RPM package can be created by commands
'make rpm' or 'setarch i586 make rpm'.
For internationalization support RHash should be compiled with gettext library
make ADDCFLAGS="-DUSE_GETTEXT"
To compile with openssl support use the following flags
make ADDCFLAGS="-DUSE_OPENSSL -DOPENSSL_RUNTIME -rdynamic" ADDLDFLAGS="-ldl"
......@@ -25,7 +28,7 @@ Windows Installation:
You need MinGW compiler and MSYS environment.
To compile the program run 'make'.
Otionally you can run 'make test'.
Optionally you can run 'make test'.
The LibRHash DLL can be created by
cd librhash && make dll test-dll
......@@ -3,7 +3,7 @@
# compile for pentiumpro: make CFLAGS="-O2 -DNDEBUG -march=i586 -mcpu=pentiumpro -fomit-frame-pointer"
# create rpm with statically linked program: make rpm ADDLDFLAGS="-static -s -Wl,--gc-sections"
CC = gcc
VERSION = 1.2.8
VERSION = 1.2.9
PREFIX = /usr/local
# using OPTFLAGS/OPTLDFLAGS for compatibilty with old scripts using this makefile
OPTFLAGS = -O2 -DNDEBUG -fomit-frame-pointer -ffunction-sections -fdata-sections
......@@ -17,12 +17,14 @@ ALLCFLAGS = -pipe $(CFLAGS) $(ADDCFLAGS) \
-Wbad-function-cast -Wmissing-prototypes -Wmissing-declarations
LDLIBRHASH = -Llibrhash -lrhash
ALLLDFLAGS = $(LDLIBRHASH) $(LDFLAGS) $(ADDLDFLAGS)
SHRDLFLAGS = librhash/librhash.so.0 $(LDFLAGS) $(ADDLDFLAGS)
HEADERS = calc_sums.h hash_print.h common_func.h hash_update.h file_mask.h file_set.h find_file.h hash_check.h output.h parse_cmdline.h rhash_main.h win_utils.h version.h
SOURCES = calc_sums.c hash_print.c common_func.c hash_update.c file_mask.c file_set.c find_file.c hash_check.c output.c parse_cmdline.c rhash_main.c win_utils.c
OBJECTS = calc_sums.o hash_print.o common_func.o hash_update.o file_mask.o file_set.o find_file.o hash_check.o output.o parse_cmdline.o rhash_main.o win_utils.o
OUTDIR =
PROGNAME = rhash
TARGET = $(OUTDIR)$(PROGNAME)
SHARED_TRG = $(TARGET)_shared
SYMLINKS = sfv-hash tiger-hash tth-hash whirlpool-hash has160-hash gost-hash ed2k-link magnet-link
SPECFILE = dist/rhash.spec
LIN_DIST_FILES = Makefile ChangeLog INSTALL COPYING README \
......@@ -45,12 +47,12 @@ LIBRHASH_FILES = librhash/algorithms.c librhash/algorithms.h \
librhash/whirlpool.h librhash/whirlpool_sbox.c librhash/test_hashes.c \
librhash/test_hashes.h librhash/torrent.h librhash/torrent.c \
librhash/util.c librhash/util.h librhash/config.h librhash/Makefile
I18N_FILES = po/rhash.pot po/ru.po
I18N_FILES = po/de.po po/en_AU.po po/es.po po/gl.po po/it.po po/ru.po
DIST_FILES = $(LIN_DIST_FILES) $(LIBRHASH_FILES) $(WIN_DIST_FILES) $(WIN_SRC_FILES) $(I18N_FILES)
WIN_SUFFIX = win32
ARCHIVE_BZIP = rhash-$(VERSION)-src.tar.bz2
ARCHIVE_GZIP = rhash-$(VERSION)-src.tar.gz
ARCHIVE_DEB_GZ = ../rhash_$(VERSION).orig.tar.gz
ARCHIVE_DEB_GZ = rhash_$(VERSION).orig.tar.gz
ARCHIVE_7Z = rhash-$(VERSION)-src.tar.7z
ARCHIVE_ZIP = rhash-$(VERSION)-$(WIN_SUFFIX).zip
WIN_ZIP_DIR = RHash-$(VERSION)-$(WIN_SUFFIX)
......@@ -74,9 +76,10 @@ uninstall: uninstall-program uninstall-symlinks
dist: gzip
gzip: check $(ARCHIVE_GZIP)
bzip: check $(ARCHIVE_BZIP)
dgz: check $(ARCHIVE_DEB_GZ)
7z: check $(ARCHIVE_7Z)
zip : $(ARCHIVE_ZIP)
win-dist : $(ARCHIVE_ZIP)
win-dist: $(ARCHIVE_ZIP)
install-program: all
$(INSTALL) -d $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)/man1 $(DESTDIR)/etc
......@@ -98,37 +101,49 @@ uninstall-symlinks:
for f in $(SYMLINKS); do rm -f $(DESTDIR)$(BINDIR)/$$f; done
install-lib-static:
cd librhash && make install-lib-static
make -C librhash install-lib-static
install-lib-shared:
cd librhash && make install-lib-shared
make -C librhash install-lib-shared
lib-static: $(LIBRHASH)
lib-shared :
cd librhash && make lib-shared
lib-shared:
make -C librhash lib-shared
test-hashes:
cd librhash && make test
test-hashes: test-lib
test-lib:
make -C librhash test
test: $(TARGET) test-hashes
test: $(TARGET) test-lib
chmod +x tests/test_$(PROGNAME).sh
tests/test_$(PROGNAME).sh
version.h : Makefile
test-shared: rhash-shared
make -C librhash test-shared
chmod +x tests/test_$(PROGNAME).sh
LD_LIBRARY_PATH=../librhash tests/test_rhash.sh ./$(SHARED_TRG)
version.h: Makefile
echo "#define VERSION \"$(VERSION)\"" > version.h
check: version.h
bindings/version.properties: Makefile
echo "version=$(VERSION)" > bindings/version.properties
check: version.h bindings/version.properties
# check version
grep -q '\* === Version $(VERSION) ===' ChangeLog
grep -q '^#define VERSION "$(VERSION)"' version.h
[ -s dist/rhash.1.html ]
$(LIBRHASH): $(LIBRHASH_FILES)
cd librhash && make lib-static
make -C librhash lib-static
$(TARGET): $(OBJECTS) $(LIBRHASH)
$(CC) $(OBJECTS) -o $(TARGET) $(ALLLDFLAGS)
$(CC) $(OBJECTS) -o $@ $(ALLLDFLAGS)
rhash-shared: $(OBJECTS) lib-shared
$(CC) $(OBJECTS) -o $(SHARED_TRG) $(SHRDLFLAGS)
# NOTE: dependences were generated by 'gcc -Ilibrhash -MM *.c'
# we are using plain old makefile style to support BSD make
......@@ -196,7 +211,7 @@ dist/rhash.1.win.html: dist/rhash.1 dist/rhash.1.win.sed
grep -q "APPDATA" dist/rhash.1.win.html
dist/rhash.1.html: dist/rhash.1
-which rman &>/dev/null && (rman -fHTML -roff dist/rhash.1 | sed -e '/<BODY/s/\(bgcolor=\)"[^"]*"/\1"white"/i' > $@)
-which rman 2>/dev/null && (rman -fHTML -roff dist/rhash.1 | sed -e '/<BODY/s/\(bgcolor=\)"[^"]*"/\1"white"/i' > $@)
dist/rhash.1.txt: dist/rhash.1
-which groff &>/dev/null && (groff -t -e -mandoc -Tascii dist/rhash.1 | sed -e 's/.\[[0-9]*m//g' > $@)
......@@ -205,32 +220,36 @@ cpp-doc:
cppdoc_cmd -title=RHash -company=Animegorodok -classdir=classdoc -module="cppdoc-standard" -overwrite -extensions="c,h" -languages="c=cpp,h=cpp" -generate-deprecations-list=false $(SOURCES) $(HEADERS) ./Documentation/CppDoc/index.html
permissions:
chmod -x $(DIST_FILES)
find . dist librhash po win32 win32/vc-2010 -maxdepth 1 -type f -exec chmod -x '{}' \;
chmod +x tests/test_$(PROGNAME).sh
$(ARCHIVE_GZIP): $(DIST_FILES)
make permissions
clean-bindings:
make -C bindings distclean
copy-dist: $(DIST_FILES) permissions
rm -rf $(PROGNAME)-$(VERSION)
mkdir $(PROGNAME)-$(VERSION)
cp -rl --parents $(DIST_FILES) $(PROGNAME)-$(VERSION)/
make -C bindings distclean
find bindings/ -type f -regex '.*\(\.\([hct]\|java\|PL\|pm\|py\|rb\|txt\|xs\)\|Makefile\|MANIFEST\|typemap\)' -exec cp -l --parents '{}' $(PROGNAME)-$(VERSION)/ \;
gzip-rhash: copy-dist
tar czf $(ARCHIVE_GZIP) $(PROGNAME)-$(VERSION)/
rm -rf $(PROGNAME)-$(VERSION)
$(ARCHIVE_BZIP): $(DIST_FILES)
make permissions
gzip-bindings:
make -C bindings gzip ARCHIVE_GZIP=../rhash-bindings-$(VERSION)-src.tar.gz
$(ARCHIVE_GZIP): clean-bindings copy-dist
make -C bindings copy-dist COPYDIR=../$(PROGNAME)-$(VERSION)/bindings
tar czf $(ARCHIVE_GZIP) $(PROGNAME)-$(VERSION)/
rm -rf $(PROGNAME)-$(VERSION)
mkdir $(PROGNAME)-$(VERSION)
cp -rl --parents $(DIST_FILES) $(PROGNAME)-$(VERSION)/
$(ARCHIVE_BZIP): clean-bindings copy-dist
make -C bindings copy-dist COPYDIR=../$(PROGNAME)-$(VERSION)/bindings
tar cjf $(ARCHIVE_BZIP) $(PROGNAME)-$(VERSION)/
rm -rf $(PROGNAME)-$(VERSION)
$(ARCHIVE_7Z): $(DIST_FILES)
make permissions
rm -rf $(PROGNAME)-$(VERSION)
mkdir $(PROGNAME)-$(VERSION)
cp -rl --parents $(DIST_FILES) $(PROGNAME)-$(VERSION)/
$(ARCHIVE_7Z): clean-bindings copy-dist
make -C bindings copy-dist COPYDIR=../$(PROGNAME)-$(VERSION)/bindings
tar cf - $(PROGNAME)-$(VERSION)/ | 7zr a -si $(ARCHIVE_7Z)
rm -rf $(PROGNAME)-$(VERSION)
......@@ -240,7 +259,7 @@ $(ARCHIVE_ZIP): $(WIN_DIST_FILES) dist/rhash.1.win.html
mkdir $(WIN_ZIP_DIR)
cp $(TARGET).exe ChangeLog $(WIN_DIST_FILES) $(WIN_ZIP_DIR)/
cp dist/rhash.1.win.html $(WIN_ZIP_DIR)/rhash-doc.html
-[ -f $(OUTDIR)libeay32.dll ] && cp $(OUTDIR)libeay32.dll $(WIN_ZIP_DIR)/
# -[ -f $(OUTDIR)libeay32.dll ] && cp $(OUTDIR)libeay32.dll $(WIN_ZIP_DIR)/
zip -9r $(ARCHIVE_ZIP) $(WIN_ZIP_DIR)
rm -rf $(WIN_ZIP_DIR)
......@@ -262,14 +281,13 @@ rpm: gzip
distclean: clean
clean:
cd librhash && make clean
rm -f *.o $(TARGET)
rm -f po/*.gmo
rm -f po/*.po~
make -C librhash clean
rm -f *.o $(SHARED_TRG) $(TARGET)
rm -f po/*.gmo po/*.po~
update-po:
xgettext *.c -k_ -cTRANSLATORS -o po/rhash.pot \
--msgid-bugs-address='rhash.admin@gmail.com' --package-name='RHash'
--msgid-bugs-address='Aleksey <rhash.admin@gmail.com>' --package-name='RHash'
for f in po/*.po; do \
msgmerge -U $$f po/rhash.pot; \
done
......
MAKE = make
RUBY = ruby
PYTHON = python
PERL = /usr/bin/perl
DESTDIR =
PREFIX = /usr/local
PERL_OPTIMIZE = -O2 -g -Wall
VERSION = $(shell sed -ne 's/^version=\(.*\)/\1/p' version.properties)
FILES = Makefile version.properties
BINDINGS = java mono perl python ruby
ARCHIVE_GZIP = rhash-bindings-$(VERSION)-src.tar.gz
COPYDIR = rhash-bindings-$(VERSION)
CP = cp -l --parents
all: configure build test
configure: configure-ruby configure-perl
build: build-java build-perl build-ruby
test: test-java test-perl test-ruby
install: install-ruby install-perl
clean: distclean
configure: $(patsubst %, configure-%, $(filter perl ruby, $(BINDINGS)))
build: $(patsubst %, build-%, $(BINDINGS))
test: $(patsubst %, test-%, $(BINDINGS))
install: $(patsubst %, install-%, $(filter perl ruby, $(BINDINGS)))
configure-perl:
cd perl && perl Makefile.PL INSTALLDIRS=vendor
......@@ -19,14 +27,20 @@ configure-ruby:
$(RUBY) -C ruby extconf.rb
build-java:
$(MAKE) -C java/ jar jar-symlink jni javadoc
$(MAKE) -C java/
build-perl:
$(MAKE) -C perl OPTIMIZE="$(PERL_OPTIMIZE)"
build-python:
# not required
build-ruby:
$(MAKE) -C ruby
build-mono:
$(MAKE) -C mono
test-java:
$(MAKE) -C java test
......@@ -36,6 +50,12 @@ test-perl:
test-ruby:
$(RUBY) -C ruby test_rhash.rb
test-mono:
$(MAKE) -C mono test
test-python:
$(PYTHON) python/test_rhash.py
install-ruby:
$(MAKE) -C ruby install DESTDIR=$(DESTDIR) sitedir=$(DESTDIR)/usr/lib/ruby
......@@ -43,7 +63,22 @@ install-perl:
$(MAKE) -C perl install DESTDIR=$(DESTDIR)
# $(MAKE) -C perl install DESTDIR=$(DESTDIR) PREFIX=$(PREFIX) SITEPREFIX=$(PREFIX)
copy-dist:
mkdir -p $(COPYDIR)
find java ruby python -type f -regex '.*\(\.\([hc]\|java\|py\|rb\|txt\)\|Makefile\)' -exec $(CP) '{}' $(COPYDIR)/ \;
find perl -type f -regex '.*\(\.\(t\|PL\|pm\|xs\)\|MANIFEST\|typemap\)' -exec $(CP) '{}' "$(COPYDIR)/" \;
find mono -type f -regex '.*\(\.\([hc]\|cs\|xml\|txt\|snk\|sln\|csproj\)\|Makefile\)' -exec $(CP) '{}' "$(COPYDIR)/" \;
$(CP) $(FILES) "$(COPYDIR)/"
gzip: distclean
rm -rf "$(COPYDIR)" $(ARCHIVE_GZIP)
make copy-dist
tar -czf $(ARCHIVE_GZIP) "$(COPYDIR)"
rm -rf "$(COPYDIR)"
distclean:
$(MAKE) -C java distclean
$(MAKE) -C mono clean
[ ! -f ruby/Makefile ] || $(MAKE) -C ruby distclean
[ ! -f perl/Makefile ] || $(MAKE) -C perl distclean
rm -f python/*.pyc
#!/usr/bin/make -f
# This file is a part of Java Bindings for Librhash
# Copyright (c) 2011, Sergey Basalaev <sbasalaev@gmail.com>
# Librhash is (c) 2011, Alexey S Kravchenko <rhash.admin@gmail.com>
# Copyright (c) 2011-2012, Sergey Basalaev <sbasalaev@gmail.com>
# Librhash is (c) 2011-2012, Aleksey Kravchenko <rhash.admin@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
......@@ -22,8 +22,9 @@ JAVAC = javac
JAVADOC = javadoc
JAVAH = javah
JAR = jar
JUNIT_CLASSPATH = /usr/share/java/junit4.jar
VERSION = $(shell sed -e 's/.*"\(.*\)".*/\1/' ../../version.h)
VERSION = $(shell sed -ne 's/^version=\(.*\)/\1/p' ../version.properties)
JAVASRC_DIR = src
CSRC_DIR = native
......@@ -36,14 +37,15 @@ JAVADOC_API_URL = http://download.oracle.com/javase/6/docs/api/
JARFILE = $(DEST_DIR)/rhash-$(VERSION).jar
all: jar jni test
all: jar jar-symlink jni javadoc
jar: compile-classes
mkdir -p $(DEST_DIR)
$(JAR) cf $(JARFILE) -C $(CLASSES_DIR) org/
jar-symlink:
ln -s rhash-$(VERSION).jar $(DEST_DIR)/rhash.jar
mkdir -p $(DEST_DIR)
ln -fs rhash-$(VERSION).jar $(DEST_DIR)/rhash.jar
compile-classes:
mkdir -p $(CLASSES_DIR)
......@@ -65,8 +67,8 @@ javadoc: clean-javadoc
-link $(JAVADOC_API_URL)
test: jar jni
$(JAVAC) -classpath $(JARFILE) $(TEST_DIR)/Test.java
$(JAVA) -classpath $(TEST_DIR):$(JARFILE) -Djava.library.path=$(DEST_DIR) Test
$(JAVAC) -classpath $(JARFILE):$(JUNIT_CLASSPATH) $(TEST_DIR)/RHashTest.java
$(JAVA) -classpath $(TEST_DIR):$(JARFILE):$(JUNIT_CLASSPATH) -Djava.library.path=$(DEST_DIR) junit.textui.TestRunner RHashTest
clean: clean-javadoc clean-jni clean-classes clean-test
......
#!/usr/bin/make -f
# This file is a part of Java Bindings for Librhash
# Copyright (c) 2011, Sergey Basalaev <sbasalaev@gmail.com>
# Librhash is (c) 2011, Alexey S Kravchenko <rhash.admin@gmail.com>
# Copyright (c) 2011-2012, Sergey Basalaev <sbasalaev@gmail.com>
# Librhash is (c) 2011-2012, Aleksey Kravchenko <rhash.admin@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
......@@ -40,7 +40,7 @@ digest.o: digest.c digest.h
$(CC) $(ALLCFLAGS) -c $< -o $@
$(LIBRARY): $(OBJECTS)
$(CC) $(LDFLAGS) -shared -o $@ $(OBJECTS)
$(CC) -shared -o $@ $(OBJECTS) $(LDFLAGS)
clean:
rm -f *.o $(LIBRARY)
......
/*
* This file is a part of Java Bindings for Librhash
* Copyright (c) 2011, Sergey Basalaev <sbasalaev@gmail.com>
* Librhash is (c) 2011, Alexey S Kravchenko <rhash.admin@gmail.com>
* Copyright (c) 2011-2012, Sergey Basalaev <sbasalaev@gmail.com>
* Librhash is (c) 2011-2012, Aleksey Kravchenko <rhash.admin@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
......@@ -18,6 +18,18 @@
#include <rhash/rhash.h>
#include <stdlib.h>
#ifdef __GNUC__
#include <stdint.h>
#define TO_RHASH(a) ((rhash)(intptr_t)(a))
#define TO_DIGEST(a) ((Digest)(intptr_t)(a))
#define TO_JLONG(a) ((jlong)(intptr_t)(a))
#else
#define TO_RHASH(a) ((rhash)(a))
#define TO_DIGEST(a) ((Digest)(a))
#define TO_JLONG(a) ((jlong)(a))
#endif /* __GNUC__ */
#include "bindings.h"
#include "digest.h"
......@@ -59,7 +71,7 @@ JNIEXPORT jlong JNICALL Java_org_sf_rhash_Bindings_rhash_1msg
//cleaning
free(msg);
//returning
return (jlong)obj;
return TO_JLONG(obj);
}
/*
......@@ -69,14 +81,35 @@ JNIEXPORT jlong JNICALL Java_org_sf_rhash_Bindings_rhash_1msg
*/
JNIEXPORT jbyteArray JNICALL Java_org_sf_rhash_Bindings_rhash_1print_1bytes
(JNIEnv *env, jclass clz, jlong ptr, jint flags) {
Digest obj = (Digest)ptr;
unsigned char output[130];
Digest obj = TO_DIGEST(ptr);
char output[130];
int len = rhash_print_bytes(output, obj->hash_data, obj->hash_len, flags);
jbyteArray arr = (*env)->NewByteArray(env, len);
(*env)->SetByteArrayRegion(env, arr, 0, len, output);
return arr;
}
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_print_magnet
* Signature: (JLjava/lang/String;I)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_sf_rhash_Bindings_rhash_1print_1magnet
(JNIEnv *env, jclass clz, jlong context, jstring filepath, jint flags) {
const char* fpath = (filepath != NULL) ?
(*env)->GetStringUTFChars(env, filepath, NULL) : NULL;
size_t len = rhash_print_magnet(NULL, fpath, TO_RHASH(context), flags, RHPR_FILESIZE);
char *buf = (char*)malloc(len);
rhash_print_magnet(buf, fpath, TO_RHASH(context), flags, RHPR_FILESIZE);
if (filepath != NULL) {
(*env)->ReleaseStringUTFChars(env, filepath, fpath);
}
jstring str = (*env)->NewStringUTF(env, buf);
free(buf);
return str;
}
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_is_base32
......@@ -104,7 +137,9 @@ JNIEXPORT jint JNICALL Java_org_sf_rhash_Bindings_rhash_1get_1digest_1size
*/
JNIEXPORT jlong JNICALL Java_org_sf_rhash_Bindings_rhash_1init
(JNIEnv *env, jclass clz, jint hash_flags) {
return (jlong)rhash_init(hash_flags);
rhash ctx = rhash_init(hash_flags);
rhash_set_autofinal(ctx, 0);
return TO_JLONG(ctx);
}
/*
......@@ -116,7 +151,7 @@ JNIEXPORT void JNICALL Java_org_sf_rhash_Bindings_rhash_1update
(JNIEnv *env, jclass clz, jlong context, jbyteArray data, jint ofs, jint len) {
void* msg = malloc(len);
(*env)->GetByteArrayRegion(env, data, ofs, len, msg);
rhash_update((rhash)context, msg, len);
rhash_update(TO_RHASH(context), msg, len);
free(msg);
}
......@@ -127,7 +162,7 @@ JNIEXPORT void JNICALL Java_org_sf_rhash_Bindings_rhash_1update
*/
JNIEXPORT void JNICALL Java_org_sf_rhash_Bindings_rhash_1final
(JNIEnv *env, jclass clz, jlong context) {
rhash_final((rhash)context, NULL);
rhash_final(TO_RHASH(context), NULL);
}
/*
......@@ -137,7 +172,7 @@ JNIEXPORT void JNICALL Java_org_sf_rhash_Bindings_rhash_1final
*/
JNIEXPORT void JNICALL Java_org_sf_rhash_Bindings_rhash_1reset
(JNIEnv *env, jclass clz, jlong context) {
rhash_reset((rhash)context);
rhash_reset(TO_RHASH(context));
}
/*
......@@ -150,8 +185,8 @@ JNIEXPORT jlong JNICALL Java_org_sf_rhash_Bindings_rhash_1print
Digest obj = malloc(sizeof(DigestStruct));
obj->hash_len = rhash_get_digest_size(hash_id);
obj->hash_data = calloc(obj->hash_len, sizeof(unsigned char));
rhash_print(obj->hash_data, (rhash)context, hash_id, RHPR_RAW);
return (jlong)obj;
rhash_print(obj->hash_data, TO_RHASH(context), hash_id, RHPR_RAW);
return TO_JLONG(obj);
}
/*
......@@ -161,7 +196,7 @@ JNIEXPORT jlong JNICALL Java_org_sf_rhash_Bindings_rhash_1print
*/
JNIEXPORT void JNICALL Java_org_sf_rhash_Bindings_rhash_1free
(JNIEnv *env, jclass clz, jlong context) {
rhash_free((rhash)context);
rhash_free(TO_RHASH(context));
}
/*
......@@ -171,7 +206,7 @@ JNIEXPORT void JNICALL Java_org_sf_rhash_Bindings_rhash_1free
*/
JNIEXPORT jboolean JNICALL Java_org_sf_rhash_Bindings_compareDigests
(JNIEnv *env, jclass clz, jlong ptr1, jlong ptr2) {
return compareDigests((Digest)ptr1, (Digest)ptr2);
return compareDigests(TO_DIGEST(ptr1), TO_DIGEST(ptr2));
}
/*
......@@ -181,7 +216,7 @@ JNIEXPORT jboolean JNICALL Java_org_sf_rhash_Bindings_compareDigests
*/
JNIEXPORT jint JNICALL Java_org_sf_rhash_Bindings_hashcodeForDigest
(JNIEnv *env, jclass clz, jlong ptr) {
return hashcodeForDigest((Digest)ptr);
return hashcodeForDigest(TO_DIGEST(ptr));
}
/*
......@@ -191,6 +226,6 @@ JNIEXPORT jint JNICALL Java_org_sf_rhash_Bindings_hashcodeForDigest
*/
JNIEXPORT void JNICALL Java_org_sf_rhash_Bindings_freeDigest
(JNIEnv *env, jclass clz, jlong ptr) {
freeDigest((Digest)ptr);
freeDigest(TO_DIGEST(ptr));
}
......@@ -39,6 +39,14 @@ JNIEXPORT jlong JNICALL Java_org_sf_rhash_Bindings_rhash_1msg
JNIEXPORT jbyteArray JNICALL Java_org_sf_rhash_Bindings_rhash_1print_1bytes
(JNIEnv *, jclass, jlong, jint);
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_print_magnet
* Signature: (JLjava/lang/String;I)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_sf_rhash_Bindings_rhash_1print_1magnet
(JNIEnv *, jclass, jlong, jstring, jint);
/*
* Class: org_sf_rhash_Bindings
* Method: rhash_is_base32
......
/*
* This file is a part of Java Bindings for Librhash
* Copyright (c) 2011, Sergey Basalaev <sbasalaev@gmail.com>
* Librhash is (c) 2011, Alexey S Kravchenko <rhash.admin@gmail.com>
* Copyright (c) 2011-2012, Sergey Basalaev <sbasalaev@gmail.com>
* Librhash is (c) 2011-2012, Aleksey Kravchenko <rhash.admin@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
......
/*
* This file is a part of Java Bindings for Librhash
* Copyright (c) 2011, Sergey Basalaev <sbasalaev@gmail.com>
* Librhash is (c) 2011, Alexey S Kravchenko <rhash.admin@gmail.com>
* Copyright (c) 2011-2012, Sergey Basalaev <sbasalaev@gmail.com>
* Librhash is (c) 2011-2012, Aleksey Kravchenko <rhash.admin@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
......
/*
* This file is a part of Java Bindings for Librhash
* Copyright (c) 2011, Sergey Basalaev <sbasalaev@gmail.com>
* Librhash is (c) 2011, Alexey S Kravchenko <rhash.admin@gmail.com>
* Copyright (c) 2011-2012, Sergey Basalaev <sbasalaev@gmail.com>
* Librhash is (c) 2011-2012, Aleksey Kravchenko <rhash.admin@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
......@@ -17,8 +17,6 @@
package org.sf.rhash;
import java.io.IOException;
/**
* Glue to the native API.
*/
......@@ -44,18 +42,28 @@ final class Bindings {
* @param data the data to process
* @param ofs offset in data array from which to start processing
* @param len data length
* @return pointer to native digest object
* @return pointer to the native digest object
*/
static native long rhash_msg(int hash_id, byte[] data, int ofs, int len);
/**
* Print text representation of a given digest.
* Prints text representation of a given digest.
*
* @param hash pointer to native digest object
* @param rhash pointer to native digest object
* @param flags output flags
* @return text representation as byte array
*/
static native byte[] rhash_print_bytes(long hash, int flags);
static native byte[] rhash_print_bytes(long rhash, int flags);
/**
* Returns magnet link for given hash context and hashing algorithms.
*
* @param rhash pointer to native digest object
* @param filename the name of the file to incorporate in magnet
* @param flags mask of hash_id values
* @return magnet string
*/
static native String rhash_print_magnet(long rhash, String filename, int flags);
/**
* Tests whether given default hash algorithm output is base32.
......@@ -75,44 +83,44 @@ final class Bindings {
/**
* Creates new hash context.
* @param flags mask of hash_id values
* @return pointer to native hash context
* @return pointer to the native hash context
*/
static native long rhash_init(int flags);
/**
* Updates hash context with given data.
* @param context pointer to native hash context
* @param data data to process
* @param ofs index of the first byte to process
* @param len count of bytes to process
* @param rhash pointer to native hash context
* @param data data to process
* @param ofs index of the first byte to process
* @param len count of bytes to process
*/
static native void rhash_update(long context, byte[] data, int ofs, int len);
static native void rhash_update(long rhash, byte[] data, int ofs, int len);
/**
* Finalizes hash context.
* @param context pointer to native hash context
* @param rhash pointer to native hash context
*/
static native void rhash_final(long context);
static native void rhash_final(long rhash);
/**
* Resets hash context.
* @param context pointer to native hash context
* @param rhash pointer to native hash context
*/
static native void rhash_reset(long context);
static native void rhash_reset(long rhash);
/**
* Generates message digest for given context and hash_id.
* @param context pointer to native hash context
* @param rhash pointer to native hash context
* @param hash_id id of hashing algorithm
* @return pointer to native digest
*/
static native long rhash_print(long context, int hash_id);
static native long rhash_print(long rhash, int hash_id);
/**
* Frees hash context.
* @param context pointer to native hash context
* @param rhash pointer to native hash context
*/
static native void rhash_free(long context);
static native void rhash_free(long rhash);
/**
* Compares two native hash objects.
......
/*
* This file is a part of Java Bindings for Librhash
* Copyright (c) 2011, Sergey Basalaev <sbasalaev@gmail.com>
* Librhash is (c) 2011, Alexey S Kravchenko <rhash.admin@gmail.com>
* Copyright (c) 2011-2012, Sergey Basalaev <sbasalaev@gmail.com>
* Librhash is (c) 2011-2012, Aleksey Kravchenko <rhash.admin@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
......
/*
* This file is a part of Java Bindings for Librhash
* Copyright (c) 2011, Sergey Basalaev <sbasalaev@gmail.com>
* Librhash is (c) 2011, Alexey S Kravchenko <rhash.admin@gmail.com>
* Copyright (c) 2011-2012, Sergey Basalaev <sbasalaev@gmail.com>
* Librhash is (c) 2011-2012, Aleksey Kravchenko <rhash.admin@gmail.com>
*