--- /dev/null
+# 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 $<
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.
Load common targets
========================================= -->
<!-- Put your language target (java/c++-ant/c++-autotool/perl) here -->
- <!-- <import file="${global.targets-xxx.file}" /> -->
+ <import file="${global.targets-simple_make.file}" />
<!-- =========================================
Load version file
<target name="localinit"
description="Module specific initialization tasks">
+ <antcall target="lbmakefiles" />
</target>
<target name="localcompile"
--- /dev/null
+#ifndef _GLITE_JOBID_H
+#define _GLITE_JOBID_H
+
+/*!
+ * \file cjobid.h
+ * \brief L&B consumer API
+ */
+
+#ident "$Header$"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct _glite_lbu_JobId *glite_lbu_JobId;
+
+#define GLITE_WMSC_JOBID_DEFAULT_PORT 9000 /**< Default port where bookkeeping server listens */
+#define GLITE_WMSC_JOBID_PROTO_PREFIX "https://" /**< JobId protocol prefix */
+
+
+/* All the pointer functions return malloc'ed objects (or NULL on error) */
+
+/**
+ * Create a Job ID.
+ * See the lb_draft document for details on its construction and components
+ * \param bkserver book keeping server hostname
+ * \param port port for the bk service
+ * \param jobid new created job id
+ * \ret al 0 success
+ * \retval EINVAL invalid bkserver
+ * \retval ENOMEM if memory allocation fails
+ */
+int glite_lbu_JobIdCreate(const char * bkserver, int port, glite_lbu_JobId * jobid);
+
+/**
+ * Recreate a Job ID
+ * \param bkserver bookkeeping server hostname
+ * \param port port for the bk service
+ * \param unique string which represent created jobid (if NULL then new
+ * one is created)
+ * \param jobid new created job id
+ * \retval 0 success
+ * \retval EINVAL invalid bkserver
+ * \retval ENOMEM if memory allocation fails
+ */
+int glite_lbu_JobIdRecreate(const char *bkserver, int port, const char * unique, glite_lbu_JobId * jobid);
+
+/**
+ * Create copy of Job ID
+ * \param in jobid for duplication
+ * \param jobid duplicated jobid
+ * \retval 0 for success
+ * \retval EINVAL invalid jobid
+ * \retval ENOMEM if memory allocation fails
+ */
+int glite_lbu_JobIdDup(const glite_lbu_JobId in, glite_lbu_JobId * jobid);
+
+/*
+ * Free jobid structure
+ * \param jobid for dealocation
+ */
+void glite_lbu_JobIdFree(glite_lbu_JobId jobid);
+
+/**
+ * Parse Job ID string and creates jobid structure
+ * \param jobidstr string representation of jobid
+ * \param jobid parsed job id
+ * \retval 0 for success
+ * \retval EINVAL jobidstr can't be parsed
+ * \retval ENOMEM if memory allocation fails
+ */
+int glite_lbu_JobIdParse(const char* jobidstr, glite_lbu_JobId * jobid);
+
+/**
+ * Unparse Job ID (produce the string form of JobId).
+ * \param jobid to be converted to string
+ * \return allocated string which represents jobid
+ */
+char* glite_lbu_JobIdUnparse(const glite_lbu_JobId jobid);
+
+/**
+ * Extract bookkeeping server address (address:port)
+ * \param jobid from which the bkserver address should be extracted
+ * \retval pointer to allocated string with bkserver address
+ * \retval NULL if jobid is 0 or memory allocation fails
+ */
+char* glite_lbu_JobIdGetServer(const glite_lbu_JobId jobid);
+
+/**
+ * Extract bookkeeping server address and port
+ * \param jobid from which the bkserver address should be extracted
+ * \param srvName pointer where to return server name
+ * \param srvPort pointer where to return server port
+ * */
+void glite_lbu_JobIdGetServerParts(const glite_lbu_JobId jobid, char **srvName, unsigned int *srvPort);
+
+/**
+ * Extract unique string
+ * \param jobid
+ * \retval pointer to allocated unique string representing jobid
+ * \retval NULL if jobid is 0 or memory allocation fails
+ */
+char* glite_lbu_JobIdGetUnique(const glite_lbu_JobId jobid);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _GLITE_JOBID_H */
+# temporary hack before lb-utils are integrated
+
+lb-utils.subsystem.name = org.glite.lb-utils
+lb-utils.subsystem.prefix = lb-utils
Revision history:
$Log$
+ Revision 1.1.1.1 2006/07/14 06:59:06 akrenek
+ module created
+
Revision 1.3 2004/07/20 16:08:30 flammer
Changed incorrect my_... instead of .._template entries for subsystem and component.
-->
<project name="lb-utils jobid component configuration properties">
+ <target name="lbmakefiles">
+ <exec executable="ln" failonerror="true">
+ <arg line="-fs ${component.dir}/Makefile ${module.build.dir}/Makefile"/>
+ </exec>
+
+ <echo file="${module.build.dir}/Makefile.inc">
+top_srcdir=..
+builddir=build
+stagedir=${stage.abs.dir}
+</echo>
+ </target>
+
</project>
-module.version = 0.0.0
-module.age = 0
\ No newline at end of file
+module.version = 1.0.0
+module.age = 0
--- /dev/null
+#ident "$Header$"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <assert.h>
+
+#include <netdb.h>
+#include <sys/time.h>
+#include <unistd.h>
+
+#include <ctype.h>
+
+#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;
+}
--- /dev/null
+#ident "$Header$"
+
+#include <openssl/md5.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#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);
+}
--- /dev/null
+#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 */