compiles now
authorMichal Voců <michal@ruk.cuni.cz>
Thu, 9 Aug 2007 13:19:49 +0000 (13:19 +0000)
committerMichal Voců <michal@ruk.cuni.cz>
Thu, 9 Aug 2007 13:19:49 +0000 (13:19 +0000)
org.glite.jobid.api-c/Makefile
org.glite.jobid.api-c/interface/cjobid.h
org.glite.jobid.api-c/src/cjobid.c
org.glite.jobid.api-c/src/strmd5.c [new file with mode: 0755]
org.glite.jobid.api-c/src/strmd5.h [new file with mode: 0755]

index 998b75e..af6db12 100644 (file)
@@ -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}
index aff406d..9b38c81 100755 (executable)
@@ -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)
index 7ff320c..62b52e4 100644 (file)
@@ -5,12 +5,12 @@
 #include <string.h>
 #include <errno.h>
 #include <assert.h>
-
+#include <ctype.h>
 #include <netdb.h>
 #include <sys/time.h>
 #include <unistd.h>
 
-#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 (executable)
index 0000000..997945f
--- /dev/null
@@ -0,0 +1,118 @@
+#ident "$Header$"
+
+#include <openssl/md5.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#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 (executable)
index 0000000..c5d76b6
--- /dev/null
@@ -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 */