From: Michal Voců Date: Thu, 9 Aug 2007 13:19:49 +0000 (+0000) Subject: compiles now X-Git-Tag: glite-yaim-myproxy_R_4_0_0_2~16 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=6b6769995a94e20f5e6767f2fc1bf3d258839a18;p=jra1mw.git compiles now --- diff --git a/org.glite.jobid.api-c/Makefile b/org.glite.jobid.api-c/Makefile index 998b75e..af6db12 100644 --- a/org.glite.jobid.api-c/Makefile +++ b/org.glite.jobid.api-c/Makefile @@ -19,7 +19,7 @@ VPATH=${top_srcdir}/src:${top_srcdir}/interface:${top_srcdir}/test DEBUG:=-g -O0 -Wall CFLAGS:=${DEBUG} \ - -I${top_srcdir}/interface \ + -I${top_srcdir}/interface -I${top_srcdir}/src \ ${COVERAGE_FLAGS} \ -D_GNU_SOURCE @@ -29,7 +29,7 @@ LINK:=libtool --mode=link ${CC} ${LDFLAGS} LINKXX:=libtool --mode=link ${CXX} ${LDFLAGS} INSTALL:=libtool --mode=install install -LIBOBJS:=cjobid.o +LIBOBJS:=cjobid.o strmd5.o HDRS:=cjobid.h LIBLOBJS:=${LIBOBJS:.o=.lo} diff --git a/org.glite.jobid.api-c/interface/cjobid.h b/org.glite.jobid.api-c/interface/cjobid.h index aff406d..9b38c81 100755 --- a/org.glite.jobid.api-c/interface/cjobid.h +++ b/org.glite.jobid.api-c/interface/cjobid.h @@ -88,7 +88,7 @@ int glite_jobid_parse(const char* jobidstr, glite_jobid_t * jobid); * \param jobid to be converted to string * \return allocated string which represents jobid */ -char* glite_jobid_unparse(const glite_jobid_t jobid); +char* glite_jobid_unparse(glite_jobid_const_t jobid); /** * Extract bookkeeping server address (address:port) diff --git a/org.glite.jobid.api-c/src/cjobid.c b/org.glite.jobid.api-c/src/cjobid.c index 7ff320c..62b52e4 100644 --- a/org.glite.jobid.api-c/src/cjobid.c +++ b/org.glite.jobid.api-c/src/cjobid.c @@ -5,12 +5,12 @@ #include #include #include - +#include #include #include #include -#include "glite/jobid/cjobid.h" +#include "cjobid.h" #include "strmd5.h" struct _edg_wlc_JobId { diff --git a/org.glite.jobid.api-c/src/strmd5.c b/org.glite.jobid.api-c/src/strmd5.c new file mode 100755 index 0000000..997945f --- /dev/null +++ b/org.glite.jobid.api-c/src/strmd5.c @@ -0,0 +1,118 @@ +#ident "$Header$" + +#include +#include +#include +#include + +#include "strmd5.h" + +#warning Thread unsafe! +static char mbuf[33]; + +static 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; + 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; +} + +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); +} diff --git a/org.glite.jobid.api-c/src/strmd5.h b/org.glite.jobid.api-c/src/strmd5.h new file mode 100755 index 0000000..c5d76b6 --- /dev/null +++ b/org.glite.jobid.api-c/src/strmd5.h @@ -0,0 +1,28 @@ +#ifndef _GLITE_STRMD5_H +#define _GLITE_STRMD5_H + +#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); + +#endif /* _GLITE_STRMD5_H */