From: Aleš Křenek Date: Tue, 18 Jul 2006 14:24:30 +0000 (+0000) Subject: "ant stage" works, "dist" is broken -- I don't care yet X-Git-Tag: gridsite-core_R_1_3_2~49 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=b1c492b62ca082c6fed663ba39703b73f9fe75f0;p=jra1mw.git "ant stage" works, "dist" is broken -- I don't care yet --- diff --git a/org.glite.lb-utils.jobid/Makefile b/org.glite.lb-utils.jobid/Makefile new file mode 100644 index 0000000..31ba0aa --- /dev/null +++ b/org.glite.lb-utils.jobid/Makefile @@ -0,0 +1,100 @@ +# Default values +top_srcdir=. +builddir=build +top_builddir=${top_srcdir}/${builddir} +stagedir=. +distdir=. +globalprefix=glite +package=glite-lb-utils-jobid +version=0.0.0 +PREFIX=/opt/glite +lbuprefix=lbu + +glite_location=/opt/glite + +-include Makefile.inc +-include ../project/version.properties + +version=${module.version} + +VPATH=${top_srcdir}/src:${top_srcdir}/test::${top_srcdir}/doc + +CC=gcc + +DEBUG:=-g -O0 -Wall + +CFLAGS:=${DEBUG} -I${top_srcdir}/src -I${top_srcdir}/interface -I. -D_GNU_SOURCE + +COMPILE:=libtool --mode=compile ${CC} +LINK:=libtool --mode=link ${CC} -rpath ${stagedir}/lib ${LDFLAGS} +INSTALL:=libtool --mode=install install + +OBJS:=cjobid.o strmd5.o +LOBJS:=${OBJS:.o=.lo} + +HDRS:=cjobid.h + +STATICLIB:=libglite_lbu_jobid.a +LTLIB:=libglite_lbu_jobid.la + +default: all + +all compile: ${STATICLIB} ${LTLIB} + +# to use libtool versioning correcty, we should have: +# +# current = major + minor + offset +# revision = patch +# age = minor +# +# where offset is a sum of maximal released minor's of all previous major's +# +# version_info=-version-info `echo ${version} | cut -d. -f1,2 | tr . :` + +# counted minors: n/a +offset=0 + +version_info:=-version-info ${shell \ + perl -e '$$,=":"; @F=split "\\.","${version}"; print $$F[0]+$$F[1]+${offset},$$F[2],$$F[1]' } + +${STATICLIB}: ${OBJS} + ar crv $@ ${OBJS} + ranlib $@ + +${LTLIB}: ${OBJS} + ${LINK} ${version_info} -o $@ ${LOBJS} + +stage: compile + $(MAKE) install PREFIX=${stagedir} DOSTAGE=yes + +check: + @true + +dist: distsrc distbin + +distsrc: + mkdir -p ${top_srcdir}/${package}-${version} + cd ${top_srcdir} && GLOBIGNORE="${package}-${version}" && cp -Rf * ${package}-${version} + cd ${top_srcdir} && tar -czf ${distdir}/${package}-${version}_src.tar.gz --exclude-from=project/tar_exclude ${package}-${version} + rm -rf ${top_srcdir}/${package}-${version} + +distbin: + $(MAKE) install PREFIX=`pwd`/tmpbuilddir${stagedir} + save_dir=`pwd`; cd tmpbuilddir${stagedir} && tar -czf $$save_dir/${top_srcdir}/${distdir}/${package}-${version}_bin.tar.gz *; cd $$save_dir + rm -rf tmpbuilddir + +install: + mkdir -p ${PREFIX}/lib + mkdir -p ${PREFIX}/share/doc/${package}-${version} + ${INSTALL} -m 644 ${LTLIB} ${PREFIX}/lib + ${INSTALL} -m 644 ${top_srcdir}/LICENSE ${PREFIX}/share/doc/${package}-${version} + if [ x${DOSTAGE} = xyes ]; then \ + mkdir -p ${PREFIX}/include/${globalprefix}/${lbuprefix} ; \ + (cd ${top_srcdir}/interface && install -m 644 ${HDRS} ${PREFIX}/include/${globalprefix}/${lbuprefix}) ; \ + install -m 644 ${STATICLIB} ${PREFIX}/lib; \ + fi + +clean: + +%.o: %.c + ${COMPILE} ${CFLAGS} -c $< diff --git a/org.glite.lb-utils.jobid/build.xml b/org.glite.lb-utils.jobid/build.xml index c197b7a..810681c 100644 --- a/org.glite.lb-utils.jobid/build.xml +++ b/org.glite.lb-utils.jobid/build.xml @@ -20,6 +20,9 @@ Revision history: $Log$ + Revision 1.1.1.1 2006/07/14 06:59:06 akrenek + module created + Revision 1.7 2006/04/26 11:39:55 flammer Corrected wrong template syntax. @@ -95,7 +98,7 @@ Load common targets ========================================= --> - + + + + + + + +top_srcdir=.. +builddir=build +stagedir=${stage.abs.dir} + + + diff --git a/org.glite.lb-utils.jobid/project/version.properties b/org.glite.lb-utils.jobid/project/version.properties index 6f1f8ab..52a0f68 100755 --- a/org.glite.lb-utils.jobid/project/version.properties +++ b/org.glite.lb-utils.jobid/project/version.properties @@ -1,2 +1,2 @@ -module.version = 0.0.0 -module.age = 0 \ No newline at end of file +module.version = 1.0.0 +module.age = 0 diff --git a/org.glite.lb-utils.jobid/src/cjobid.c b/org.glite.lb-utils.jobid/src/cjobid.c new file mode 100755 index 0000000..6d6a73f --- /dev/null +++ b/org.glite.lb-utils.jobid/src/cjobid.c @@ -0,0 +1,260 @@ +#ident "$Header$" + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include "cjobid.h" +#include "strmd5.h" + +struct _glite_lbu_JobId { + char *id; /* unique job identification */ + /* additional information */ + char *BShost;/* bookkeeping server hostname */ + unsigned int BSport; /* bookkeeping server port */ + char *info; /* additional information (after ? in URI) */ +}; + +int glite_lbu_JobIdCreate(const char *bkserver, int port, glite_lbu_JobId *jobId) +{ + return glite_lbu_JobIdRecreate(bkserver, port, NULL, jobId); +} + + +int glite_lbu_JobIdRecreate(const char* bkserver, int port, const char *unique, glite_lbu_JobId *jobId) +{ + glite_lbu_JobId out; + char hostname[200]; /* used to hold string for encrypt */ + struct timeval tv; + int skip; + char* portbeg; + + struct hostent* he; + + if (!bkserver) + return EINVAL; + + if (unique == NULL) { + gethostname(hostname, 100); + he = gethostbyname(hostname); + assert(he->h_length > 0); + gettimeofday(&tv, NULL); + srandom(tv.tv_usec); + + skip = strlen(hostname); + skip += sprintf(hostname + skip, "-IP:0x%x-pid:%d-rnd:%d-time:%d:%d", + *((int*)he->h_addr_list[0]), getpid(), (int)random(), + (int)tv.tv_sec, (int)tv.tv_usec); + } + + *jobId = NULL; + out = (glite_lbu_JobId) malloc (sizeof(*out)); + if (!out) + return ENOMEM; + + memset(out, 0, sizeof(*out)); + + /* check if it begins with prefix */ + /* unsupported */ + if (strncmp(bkserver, GLITE_WMSC_JOBID_PROTO_PREFIX, sizeof(GLITE_WMSC_JOBID_PROTO_PREFIX)-1) == 0) + return EINVAL; + + out->BShost = strdup(bkserver); + portbeg = strchr(out->BShost, ':'); + if (portbeg) { + *portbeg = 0; + /* try to get port number */ + if (port == 0) + port = atoi(portbeg + 1); + } + + if (port == 0) + port = GLITE_WMSC_JOBID_DEFAULT_PORT; + + out->BSport = port; + + out->id = (unique) ? strdup(unique) : str2md5base64(hostname); + //printf("Encrypt: %s\nBASE64 %s\n", hostname, out->id); + + if (!out->id || !out->BShost) { + glite_lbu_JobIdFree(out); + return ENOMEM; + } + + *jobId = out; + return 0; +} + + +int glite_lbu_JobIdDup(const glite_lbu_JobId in, glite_lbu_JobId *out) +{ + glite_lbu_JobId jid; + *out = NULL; + if (in == NULL) + return 0; + + jid = malloc(sizeof(*jid)); + if (!jid) + return ENOMEM; + + memset(jid, 0,sizeof(*jid)); + jid->BShost = strdup(in->BShost); + jid->id = strdup(in->id); + if (in->info) + jid->info = strdup(in->info); + + if (jid->BShost == NULL || jid->id == NULL) { + glite_lbu_JobIdFree(jid); + return ENOMEM; + } + + jid->BSport = in->BSport; + *out = jid; + return 0; +} + + +// XXX +// use recreate +// parse name, port, unique +int glite_lbu_JobIdParse(const char *idString, glite_lbu_JobId *jobId) +{ + char *pom, *pom1, *pom2; + glite_lbu_JobId out; + + *jobId = NULL; + + out = (glite_lbu_JobId) malloc (sizeof(*out)); + if (out == NULL ) + return ENOMEM; + + memset(out,0,sizeof(*out)); + + if (strncmp(idString, GLITE_WMSC_JOBID_PROTO_PREFIX, sizeof(GLITE_WMSC_JOBID_PROTO_PREFIX) - 1)) { + out->BShost = (char *) NULL; + out->BSport = 0; + + free(out); + return EINVAL; + } + + pom = strdup(idString + sizeof(GLITE_WMSC_JOBID_PROTO_PREFIX) - 1); + pom1 = strchr(pom, '/'); + pom2 = strchr(pom, ':'); + + if (!pom1) { free(pom); free(out); return EINVAL; } + + if ( pom2 && (pom1 > pom2)) { + pom[pom2-pom] = '\0'; + out->BShost = strdup(pom); + pom[pom1-pom] = '\0'; + out->BSport = (unsigned int) strtoul(pom2 + 1,NULL,10); + } else { + pom[pom1-pom] = '\0'; + out->BShost = strdup(pom); + out->BSport = GLITE_WMSC_JOBID_DEFAULT_PORT; + } + + /* XXX: localhost not supported in jobid + if (!strncmp(out->BShost,"localhost",9) { + free(pom); + free(out->BShost); + free(out); + return EINVAL; + } + */ + + /* additional info from URI */ + pom2 = strchr(pom1+1,'?'); + if (pom2) { + *pom2 = 0; + out->info = strdup(pom2+1); + } + + /* extract the unique part */ + out->id = strdup(pom1+1); + + for (pom1 = out->BShost; *pom1; pom1++) + if (isspace(*pom1)) break; + + for (pom2 = out->id; *pom2; pom2++) + if (isspace(*pom2)) break; + + if (*pom1 || *pom2) { + free(pom); + glite_lbu_JobIdFree(out); + return EINVAL; + } + + free(pom); + *jobId = out; + return 0; +} + + +void glite_lbu_JobIdFree(glite_lbu_JobId job) +{ + if (job) { + free(job->id); + free(job->BShost); + free(job->info); + free(job); + } +} + + +char* glite_lbu_JobIdUnparse(const glite_lbu_JobId jobid) +{ + char *out, port[40]; + + if (!jobid) + return NULL; + + if (jobid->BSport) + sprintf(port,":%d",jobid->BSport); + else + *port = 0; + + asprintf(&out, GLITE_WMSC_JOBID_PROTO_PREFIX"%s%s/%s%s%s", + jobid->BShost,port, + jobid->id, + (jobid->info ? "?" : ""), + (jobid->info ? jobid->info : "")); + + return out; +} + + +char* glite_lbu_JobIdGetServer(const glite_lbu_JobId jobid) +{ + char *bs = NULL; + + if (jobid) + asprintf(&bs, "%s:%u", jobid->BShost, + jobid->BSport ? jobid->BSport : GLITE_WMSC_JOBID_DEFAULT_PORT); + + return bs; +} + + +void glite_lbu_JobIdGetServerParts(const glite_lbu_JobId jobid, char **srvName, unsigned int *srvPort) +{ + if (jobid) { + *srvName = strdup(jobid->BShost); + *srvPort = jobid->BSport ? jobid->BSport : GLITE_WMSC_JOBID_DEFAULT_PORT; + } +} + + +char* glite_lbu_JobIdGetUnique(const glite_lbu_JobId jobid) +{ + return jobid ? strdup(jobid->id) : NULL; +} diff --git a/org.glite.lb-utils.jobid/src/strmd5.c b/org.glite.lb-utils.jobid/src/strmd5.c new file mode 100755 index 0000000..775aee8 --- /dev/null +++ b/org.glite.lb-utils.jobid/src/strmd5.c @@ -0,0 +1,122 @@ +#ident "$Header$" + +#include +#include +#include +#include + +#include "strmd5.h" + +#if USE_MBUF /* let's try without it */ +#warning Thread unsafe! +static char mbuf[33]; +#endif + +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; +} + +#ifdef USE_MBUF +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; +} +#endif + +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.lb-utils.jobid/src/strmd5.h b/org.glite.lb-utils.jobid/src/strmd5.h new file mode 100755 index 0000000..27d8544 --- /dev/null +++ b/org.glite.lb-utils.jobid/src/strmd5.h @@ -0,0 +1,30 @@ +#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) + */ + +#ifdef USE_MBUF +char *strmd5(const char *src, unsigned char *dst); +#endif + +/** + * 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 */