LIB:=libglite_jobid.la
+TEST_LIBS:=-L${cppunit_prefix}/lib -lcppunit -ldl
+TEST_INC:=-I${cppunit_prefix}/include
+
compile all: ${LIB}
offset=0
${LIB}: ${LIBOBJS}
${LINK} ${version_info} -o $@ ${LIBLOBJS} -rpath ${PREFIX}/lib
-check: compile
-#
+check: compile base64_test
+ ./base64_test base64_test.xml
+
+base64_test: %: %.cpp compile
+ ${CXX} -c ${CFLAGS} ${TEST_INC} $<
+ ${LINKXX} -o $@ $@.o ${LIB} ${TEST_LIBS}
clean:
rm -rvf *.o *.lo .libs lib* *.c *.cpp *.h
#ifndef _GLITE_STRMD5_H
#define _GLITE_STRMD5_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#ident "$Header$"
/* Compute MD5 sum of the first argument.
*/
char *str2md5base64(const char *src);
+int base64_encode(const void *enc, int enc_size, char *out, int out_max_size);
+int base64_decode(const char *enc,char *out,int out_size);
+
+#ifdef __cplusplus
+};
+#endif
+
#endif /* _GLITE_STRMD5_H */
#include "md5_dgst.c"
-#warning Thread unsafe!
static char mbuf[33];
+static const char* b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
+static char *b64r;
-static int base64_encode(const void *enc, int enc_size, char *out, int out_max_size)
+int base64_encode(const void *enc, int enc_size, char *out, int out_max_size)
{
- static const char* b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
unsigned char* enc_buf = (unsigned char*)enc;
int out_size = 0;
return -1;
}
+int base64_decode(const char *enc,char *out,int max_out_size)
+{
+ unsigned int bits = 0;
+ int shift = 0;
+ int out_size = 0;
+
+ if (!b64r) {
+ int i;
+ b64r = calloc(128,1);
+
+ for (i=0; b64[i]; i++) b64r[(int)b64[i]] = i;
+ }
+
+ while (*enc && *enc != '=') {
+ bits <<= 6;
+ bits |= b64r[(int)*enc++];
+ shift += 6;
+
+ while (shift >= 8) {
+ if (out_size >= max_out_size) return -1;
+ shift -= 8;
+ *out++ = (bits >> shift) & 0xff;
+ out_size++;
+ }
+ }
+
+ return out_size;
+}
+
char *strmd5(const char *s, unsigned char *digest)
{
MD5_CTX md5;
--- /dev/null
+#include <assert.h>
+#include <fstream>
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/XmlOutputter.h>
+#include <cppunit/TestRunner.h>
+#include <cppunit/TestResult.h>
+#include <cppunit/TestResultCollector.h>
+
+#include "strmd5.h"
+
+class Base64Test: public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(Base64Test);
+ CPPUNIT_TEST(test);
+ CPPUNIT_TEST_SUITE_END();
+public:
+ void test();
+};
+
+void Base64Test::test()
+{
+ int i;
+ unsigned char in[2000], b[4000], out[2000];
+
+ srandom(0xDEAD);
+ in[0] = 'x';
+ for (i=1; i<2000; i++) {
+ char s[20];
+ int len;
+ sprintf(s,"%d",i);
+ in[i] = random() % 256;
+
+ std::cerr << '.';
+
+ base64_encode(in,i,(char *) b,sizeof b);
+ len = base64_decode((const char *) b,(char *) out,sizeof out);
+
+ CPPUNIT_ASSERT_MESSAGE(std::string("len"),i == len);
+ CPPUNIT_ASSERT_MESSAGE(std::string(s),!memcmp(in,out,i));
+ }
+ std::cerr << std::endl;
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(Base64Test);
+
+
+int main (int argc,const char *argv[])
+{
+ CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
+
+ assert(argc == 2);
+ std::ofstream xml(argv[1]);
+
+ CppUnit::TestResult controller;
+ CppUnit::TestResultCollector result;
+ controller.addListener( &result );
+
+ CppUnit::TestRunner runner;
+ runner.addTest(suite);
+ runner.run(controller);
+
+ CppUnit::XmlOutputter xout( &result, xml );
+ CppUnit::CompilerOutputter tout( &result, std::cout);
+ xout.write();
+ tout.write();
+
+ return result.wasSuccessful() ? 0 : 1 ;
+}
INSTALL:=libtool --mode=install install
COMPILE:=libtool --mode=compile ${CC} ${CFLAGS}
-HDRS:=types.h context.h strmd5.h attr.h known_attr.h backend.h builtin_plugins.h file_plugin.h
+HDRS:=types.h context.h attr.h known_attr.h backend.h builtin_plugins.h file_plugin.h
-SRCS:=context.c strmd5.c attr.c utils.c
+SRCS:=context.c attr.c utils.c
OBJS:=${SRCS:.c=.lo}
THROBJS:=${OBJS:.o=.thr.lo}
-LIBS:=-L${globus_prefix}/lib -lcrypto_${nothrflavour}
+LIBS:=-L${globus_prefix}/lib -lcrypto_${nothrflavour} -L${stagedir}/lib -lglite_jobid
THRLIBS:=-L${globus_prefix}/lib -lcrypto_${thrflavour}
commonlib:= libglite_jp_common_${nothrflavour}.la
${commonlib_thr}: ${THROBJS}
${LINK} -o $@ ${THROBJS} ${THRLIBS}
-check: base64_test type_test
- ./base64_test base64_test.xml
+check: type_test
./type_test type_test.xml
-type_test base64_test: %: %.cpp compile
+type_test: %: %.cpp compile
${CXX} -c ${CFLAGS} ${TEST_INC} $<
${LINKXX} -o $@ $@.o ${commonlib} ${TEST_LIBS}
+++ /dev/null
-#ifndef _GLITE_STRMD5_H
-#define _GLITE_STRMD5_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ident "$Header$"
-
-/* Compute MD5 sum of the first argument.
- * The sum is returned in the 16-byte array pointed to by 2nd argument
- * (if not NULL)
- *
- * Return value: ASCII string of the sum, i.e. 32 characters [0-9a-f]
- * (pointer to static area, changed by subsequent calls)
- */
-
-char *strmd5(const char *src, unsigned char *dst);
-
-/**
- * Returns: allocated 32bytes long ASCII string with md5 sum
- * of the first argument
- */
-char *str2md5(const char *src);
-
-/**
- * Returns: allocated 22bytes long ASCII string with md5 sum in base64
- * format of the source argument
- */
-char *str2md5base64(const char *src);
-
-int base64_encode(const void *enc, int enc_size, char *out, int out_max_size);
-int base64_decode(const char *enc,char *out,int out_size);
-
-#ifdef __cplusplus
-};
-#endif
-
-
-#endif /* _GLITE_STRMD5_H */
#include <string.h>
#include <errno.h>
-#include "strmd5.h"
+#include "glite/jobid/strmd5.h"
#include "types.h"
#include "attr.h"
#include "type_plugin.h"
+++ /dev/null
-#include <openssl/md5.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "strmd5.h"
-
-static char mbuf[33];
-
-static const char* b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
-
-static char *b64r;
-
-int base64_encode(const void *enc, int enc_size, char *out, int out_max_size)
-{
-
- unsigned char* enc_buf = (unsigned char*)enc;
- int out_size = 0;
- unsigned int bits = 0;
- unsigned int shift = 0;
-
- while ( out_size < out_max_size ) {
- if ( enc_size>0 ) {
- // Shift in byte
- bits <<= 8;
- bits |= *enc_buf;
- shift += 8;
- // Next byte
- enc_buf++;
- enc_size--;
- } else if ( shift>0 ) {
- // Pad last bits to 6 bits - will end next loop
- bits <<= 6 - shift;
- shift = 6;
- } else {
- // Terminate with Mime style '='
- *out = '=';
- out_size++;
-
- return out_size;
- }
-
- // Encode 6 bit segments
- while ( shift>=6 ) {
- shift -= 6;
- *out = b64[ (bits >> shift) & 0x3F ];
- out++;
- out_size++;
- }
- }
-
- // Output overflow
- return -1;
-}
-
-int base64_decode(const char *enc,char *out,int max_out_size)
-{
- unsigned int bits = 0;
- int shift = 0;
- int out_size = 0;
-
- if (!b64r) {
- int i;
- b64r = calloc(128,1);
-
- for (i=0; b64[i]; i++) b64r[b64[i]] = i;
- }
-
- while (*enc && *enc != '=') {
- bits <<= 6;
- bits |= b64r[*enc++];
- shift += 6;
-
- while (shift >= 8) {
- if (out_size >= max_out_size) return -1;
- shift -= 8;
- *out++ = (bits >> shift) & 0xff;
- out_size++;
- }
- }
-
- return out_size;
-}
-
-char *strmd5(const char *s, unsigned char *digest)
-{
- MD5_CTX md5;
- unsigned char d[16];
- int i;
-
- MD5_Init(&md5);
- MD5_Update(&md5,s,strlen(s));
- MD5_Final(d,&md5);
-
- if (digest) memcpy(digest,d,sizeof(d));
-
- for (i=0; i<16; i++) {
- int dd = d[i] & 0x0f;
- mbuf[2*i+1] = dd<10 ? dd+'0' : dd-10+'a';
- dd = d[i] >> 4;
- mbuf[2*i] = dd<10 ? dd+'0' : dd-10+'a';
- }
- mbuf[32] = 0;
- return (char *) mbuf;
-}
-
-char *str2md5(const char *s)
-{
- MD5_CTX md5;
- unsigned char d[16];
- char* ret = malloc(33);
- int i;
-
- if (!ret)
- return NULL;
-
- MD5_Init(&md5);
- MD5_Update(&md5, s, strlen(s));
- MD5_Final(d, &md5);
-
- for (i=0; i<16; i++) {
- int dd = d[i] & 0x0f;
- ret[2*i+1] = dd<10 ? dd+'0' : dd-10+'a';
- dd = d[i] >> 4;
- ret[2*i] = dd<10 ? dd+'0' : dd-10+'a';
- }
- ret[32] = 0;
- return ret;
-}
-
-char *str2md5base64(const char *s)
-{
- MD5_CTX md5;
- unsigned char d[16];
- char buf[50];
- int l;
-
- MD5_Init(&md5);
- MD5_Update(&md5, s, strlen(s));
- MD5_Final(d, &md5);
-
- l = base64_encode(d, 16, buf, sizeof(buf) - 1);
- if (l < 1)
- return NULL;
- buf[l - 1] = 0;
- return strdup(buf);
-}
#include <sys/types.h>
#include <sys/stat.h>
+#include "glite/jobid/strmd5.h"
#include "types.h"
#include "context.h"
-#include "strmd5.h"
#include "known_attr.h"
#include "attr.h"