--- /dev/null
+LICENSE file for EGEE Middleware
+================================
+
+Copyright (c) 2004 on behalf of the EU EGEE Project:
+The European Organization for Nuclear Research (CERN),
+Istituto Nazionale di Fisica Nucleare (INFN), Italy
+Datamat Spa, Italy
+Centre National de la Recherche Scientifique (CNRS), France
+CS Systeme d'Information (CSSI), France
+Royal Institute of Technology, Center for Parallel Computers (KTH-PDC), Sweden
+Universiteit van Amsterdam (UvA), Netherlands
+University of Helsinki (UH.HIP), Finlan
+University of Bergen (UiB), Norway
+Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+1. Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+3. The end-user documentation included with the redistribution, if
+any, must include the following acknowledgment: "This product includes
+software developed by The EU EGEE Project (http://cern.ch/eu-egee/)."
+Alternatively, this acknowledgment may appear in the software itself, if
+and wherever such third-party acknowledgments normally appear.
+
+4. The names EGEE and the EU EGEE Project must not be
+used to endorse or promote products derived from this software without
+prior written permission. For written permission, please contact
+<email address>.
+
+5. You are under no obligation whatsoever to provide anyone with any
+bug fixes, patches, or upgrades to the features, functionality or
+performance of the Software ("Enhancements") that you may develop over
+time; however, if you choose to provide your Enhancements to The EU
+EGEE Project, or if you choose to otherwise publish or distribute your
+Enhancements, in source code form without contemporaneously requiring
+end users of The EU EGEE Proejct to enter into a separate written license
+agreement for such Enhancements, then you hereby grant The EU EGEE Project
+a non-exclusive, royalty-free perpetual license to install, use, copy,
+modify, prepare derivative works, incorporate into the EGEE Middleware
+or any other computer software, distribute, and sublicense your
+Enhancements or derivative works thereof, in binary and source code
+form (if any), whether developed by The EU EGEE Project or third parties.
+
+THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL PROJECT OR ITS CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+This software consists of voluntary contributions made by many
+individuals on behalf of the EU EGEE Prject. For more information on The
+EU EGEE Project, please see http://cern.ch/eu-egee/. For more information on
+EGEE Middleware, please see http://egee-jra1.web.cern.ch/egee-jra1/
+
+
--- /dev/null
+## *********************************************************************
+## *
+## * Copyright (c) 2002 CERN and INFN on behalf of the EU DataGrid.
+## * For license conditions see LICENSE file or
+## * http://www.edg.org/license.html
+## *
+## *********************************************************************
+
+## Process this file with automake to produce Makefile.in
+
+## Subdirectories list
+SUBDIRS = src test
+
+## Default flags to run aclocal
+ACLOCAL_AMFLAGS = -I project
+
+stage:
+ @set fnord $(MAKEFLAGS); amf=$$2; \
+ dot_seen=no; \
+ target="install"; \
+ prefix_arg="prefix=$(WORKDIR)/../../stage"; \
+ list='$(SUBDIRS)'; for subdir in $$list; do \
+ echo "Making $$target $$prefix_arg in $$subdir"; \
+ if test "$$subdir" = "."; then \
+ dot_seen=yes; \
+ local_target="$$target-am"; \
+ else \
+ local_target="$$target"; \
+ fi; \
+ (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target $$prefix_arg) \
+ || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
+ done; \
+ if test "$$dot_seen" = "no"; then \
+ $(MAKE) $(AM_MAKEFLAGS) "$$target-am" $$prefix_arg || exit 1; \
+ fi; test -z "$$fail"
+
+distsrc: dist
+ mv $(distdir).tar.gz $(DISTBIN)/$(distdir)_src.tar.gz
+
+distbin:
+ @set fnord $(MAKEFLAGS); amf=$$2; \
+ dot_seen=no; \
+ target="install"; \
+ tmpdistbin="$(WORKDIR)/dist_bin"; \
+ prefix_arg="prefix=$$tmpdistbin"; \
+ list='$(SUBDIRS)'; for subdir in $$list; do \
+ echo "Making $$target $$prefix_arg in $$subdir"; \
+ if test "$$subdir" = "."; then \
+ dot_seen=yes; \
+ local_target="$$target-am"; \
+ else \
+ local_target="$$target"; \
+ fi; \
+ (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target $$prefix_arg) \
+ || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
+ done; \
+ if test "$$dot_seen" = "no"; then \
+ $(MAKE) $(AM_MAKEFLAGS) "$$target-am" $$prefix_arg || exit 1; \
+ fi; test -z "$$fail"; \
+ pushd $$tmpdistbin; \
+ $(AMTAR) -zcf $(DISTBIN)/$(distdir)_bin.tar.gz .; \
+ popd; \
+ rm -rf $$tmpdistbin
+
--- /dev/null
+#! /bin/sh
+
+mkdir -p src/autogen
+set -x
+aclocal -I project
+libtoolize --force
+autoheader
+automake --foreign --add-missing --copy
+autoconf
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ Copyright (c) 2004 on behalf of the EU EGEE Project:
+ The European Organization for Nuclear Research (CERN),
+ Istituto Nazionale di Fisica Nucleare (INFN), Italy
+ Datamat Spa, Italy
+ Centre National de la Recherche Scientifique (CNRS), France
+ CS Systeme d'Information (CSSI), France
+ Royal Institute of Technology, Center for Parallel Computers (KTH-PDC), Sweden
+ Universiteit van Amsterdam (UvA), Netherlands
+ University of Helsinki (UH.HIP), Finland
+ University of Bergen (UiB), Norway
+ Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom
+
+ Build file for the GLite WMS jobid module
+
+ Authors: Alberto Di Meglio <alberto.di.meglio@cern.ch>
+ Joachim Flammer <Joachim.Flammer@cern.ch>
+ Version info: $Id$
+ Release: $Name$
+
+ Revision history:
+ $Log$
+
+-->
+
+<project name="jobid" default="dist">
+
+ <!-- =========================================
+ Builds the GLite WMS jobid Module
+ ========================================= -->
+
+ <!-- =========================================
+ Import properties (order is important)
+ ========================================= -->
+
+ <!-- import baseline & user properties -->
+ <import file="../org.glite/project/baseline.properties.xml" />
+
+ <!-- import component build properties,
+ component properties &
+ component common properties -->
+ <import file="./project/properties.xml"/>
+
+ <!-- import subsystem build properties,
+ subsystem properties &
+ subsystem common properties -->
+ <import file="${subsystem.properties.file}"/>
+
+ <!-- import global build properties &
+ global properties -->
+ <import file="${global.properties.file}" />
+
+ <!-- =========================================
+ Load dependency property files (order is important)
+ ========================================= -->
+ <property file="${user.dependencies.file}"/>
+ <property file="${component.dependencies.file}" />
+ <property file="${subsystem.dependencies.file}" />
+ <property file="${global.dependencies.file}"/>
+
+
+ <!-- =========================================
+ Import task definitions (order is important)
+ ========================================= -->
+ <import file="${subsystem.taskdefs.file}" />
+ <import file="${global.taskdefs.file}" />
+
+ <!-- =========================================
+ Load common targets
+ ========================================= -->
+ <import file="${global.targets-external-dependencies.file}"/>
+ <import file="${global.targets-make.file}" />
+
+ <!-- =========================================
+ Load version file
+ ========================================= -->
+ <property file="${module.version.file}"/>
+
+ <!-- ==============================================
+ Local private targets
+ ============================================== -->
+
+ <target name="localinit"
+ description="Module specific initialization tasks">
+ </target>
+
+ <target name="localcompile"
+ description="Module specific compile tasks">
+ </target>
+
+ <target name="localclean"
+ description="Module specific cleaning tasks">
+ </target>
+
+</project>
--- /dev/null
+#
+# Copyright (c) 2004 on behalf of the EU EGEE Project:
+# The European Organization for Nuclear Research (CERN),
+# Istituto Nazionale di Fisica Nucleare (INFN), Italy
+# Datamat Spa, Italy
+# Centre National de la Recherche Scientifique (CNRS), France
+# CS Systeme d'Information (CSSI), France
+# Royal Institute of Technology, Center for Parallel Computers (KTH-PDC), Sweden
+# Universiteit van Amsterdam (UvA), Netherlands
+# University of Helsinki (UH.HIP), Finland
+# University of Bergen (UiB), Norway
+# Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom
+#
+# Common configure.ac file for the GLite WMS Common module
+#
+# Authors: Alberto Di Meglio <alberto.di.meglio@cern.ch>
+# Version info: $Id$
+# Release: $Name$
+#
+# Revision history:
+# $Log$
+#
+#
+
+# Process this file with autoconf to produce a configure script.
+
+AC_PREREQ(2.57)
+AC_INIT([GLite WMS jobid], [0.0.0])
+AC_CONFIG_AUX_DIR([./project])
+AM_INIT_AUTOMAKE([1.6.3 subdir-objects])
+AC_CONFIG_SRCDIR([src/jobid_namespace.h])
+
+# Notices.
+AC_COPYRIGHT([Copyright (c) 2004 The EU EGEE Project
+See LICENCE file for details
+])
+AC_REVISION([$Revision$])
+
+#Environment.
+WORKDIR=`pwd`
+AC_SUBST(WORKDIR)
+
+REPOSITORY=$WORKDIR/../../repository
+STAGE=$WORKDIR/../../stage
+
+DISTBIN=$WORKDIR/../../dist
+AC_SUBST(DISTBIN)
+
+BOOST_CFLAGS=-I$REPOSITORY/boost/1.29.1/rhel30_gcc32/include
+AC_SUBST([BOOST_CFLAGS])
+BOOST_CPPFLAGS=$BOOST_CFLAGS
+AC_SUBST([BOOST_CPPFLAGS])
+BOOST_LIBS="-L$REPOSITORY/boost/1.29.1/rhel30_gcc32/lib/release -lboost_fs -lboost_thread -lpthread -lboost_regex -lc"
+AC_SUBST([BOOST_LIBS])
+
+CLASSAD_CFLAGS=-I$REPOSITORY/classads/0.9.4/rhel30_gcc32/include
+AC_SUBST([CLASSAD_CFLAGS])
+CLASSAD_CPPFLAGS=$CLASSAD_CFLAGS
+AC_SUBST([CLASSAD_CPPFLAGS])
+CLASSAD_LIBS="-L$REPOSITORY/classads/0.9.4/rhel30_gcc32/lib -lclassad"
+AC_SUBST([CLASSAD_LIBS])
+
+GLOBUS_SSL_UTILS_CFLAGS="-I$STAGE/include"
+AC_SUBST([GLOBUS_SSL_UTILS_CFLAGS])
+#GLOBUS_SSL_UTILS_LIBS="-L$STAGE/lib -lglobus_ssl_utils"
+#AC_SUBST([GLOBUS_SSL_UTILS_LIBS])
+
+GLITE_WORKLOAD_CFLAGS="-I$STAGE/include"
+AC_SUBST([GLITE_WORKLOAD_CFLAGS])
+GLITE_WORKLOAD_COMMON_LIBS="-L$STAGE/lib -lglite_wl_exceptions"
+AC_SUBST([GLITE_WORKLOAD_COMMON_LIBS])
+
+GLOBUS_COMMON_NOTHR_LIBS="-L$REPOSITORY/globus/2.4.3/rhel30_gcc32/lib -lglobus_common_gcc32"
+AC_SUBST([GLOBUS_COMMON_NOTHR_LIBS])
+GLOBUS_COMMON_THR_LIBS="-L$REPOSITORY/globus/2.4.3/rhel30_gcc32/lib -lglobus_common_gcc32pthr"
+AC_SUBST([GLOBUS_COMMON_THR_LIBS])
+
+GLOBUS_FTP_CLIENT_NOTHR_LIBS="-L$REPOSITORY/globus/2.4.3/rhel30_gcc32/lib -lglobus_ftp_client_gcc32"
+AC_SUBST([GLOBUS_FTP_CLIENT_NOTHR_LIBS])
+GLOBUS_FTP_CLIENT_THR_LIBS="-L$REPOSITORY/globus/2.4.3/rhel30_gcc32/lib -lglobus_ftp_client_gcc32pthr"
+AC_SUBST([GLOBUS_FTP_CLIENT_THR_LIBS])
+
+GLOBUS_SSL_NOTHR_LIBS="-L$REPOSITORY/globus/2.4.3/rhel30_gcc32/lib -lssl_gcc32 -lcrypto_gcc32"
+AC_SUBST([GLOBUS_SSL_NOTHR_LIBS])
+GLOBUS_SSL_THR_LIBS="-L$REPOSITORY/globus/2.4.3/rhel30_gcc32/lib -lssl_gcc32pthr -lcrypto_gcc32pthr"
+AC_SUBST([GLOBUS_SSL_THR_LIBS])
+
+GLOBUS_CFLAGS=-I$REPOSITORY/globus/2.4.3/rhel30_gcc32/include/gcc32
+AC_SUBST([GLOBUS_CFLAGS])
+GLOBUS_CPPFLAGS=$GLOBUS_CFLAGS
+AC_SUBST([GLOBUS_CPPFLAGS])
+GLOBUS_LIBS="-L$REPOSITORY/globus/2.4.3/rhel30_gcc32/lib -lglobus_gass_copy_gcc32 -lglobus_ftp_client_gcc32 -lglobus_gass_transfer_gcc32 -lglobus_ftp_control_gcc32 -lglobus_io_gcc32 -lglobus_gss_assist_gcc32 -lglobus_gssapi_gsi_gcc32 -lglobus_gsi_proxy_core_gcc32 -lglobus_gsi_credential_gcc32 -lglobus_gsi_callback_gcc32 -lglobus_oldgaa_gcc32 -lglobus_gsi_sysconfig_gcc32 -lglobus_gsi_cert_utils_gcc32 -lglobus_openssl_error_gcc32 -lglobus_openssl_gcc32 -lglobus_proxy_ssl_gcc32 -lssl_gcc32 -lcrypto_gcc32 -lglobus_common_gcc32"
+AC_SUBST([GLOBUS_LIBS])
+
+# Checks for programs.
+AC_PROG_CC
+AC_PROG_CPP
+AC_PROG_CXX
+AC_PROG_CXXCPP
+AM_PROG_CC_C_O
+AC_PROG_LIBTOOL
+
+# Checks for libraries.
+
+# Checks for header files.
+AC_CHECK_HEADERS([fcntl.h mntent.h sys/vfs.h syslog.h unistd.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_HEADER_STDBOOL
+AC_C_CONST
+AC_C_INLINE
+AC_TYPE_OFF_T
+AC_TYPE_SIZE_T
+AC_CHECK_MEMBERS([struct stat.st_rdev])
+AC_TYPE_UID_T
+AC_CHECK_TYPES([ptrdiff_t])
+
+# Checks for library functions.
+AC_HEADER_STDC
+AC_FUNC_ERROR_AT_LINE
+AC_FUNC_GETMNTENT
+AC_FUNC_MEMCMP
+AC_FUNC_STAT
+AC_FUNC_STRFTIME
+AC_FUNC_VPRINTF
+AC_CHECK_FUNCS([bzero endpwent ftruncate getmntent memset mkdir pow strerror strtol])
+
+# Configuration items
+AC_PREFIX_DEFAULT([/opt/glite])
+AM_CONFIG_HEADER([src/autogen/config.h])
+AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([src/Makefile])
+AC_CONFIG_FILES([src/jobid/Makefile])
+AC_CONFIG_FILES([test/Makefile])
+
+AC_OUTPUT
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2004 on behalf of the EU EGEE Project:
+ The European Organization for Nuclear Research (CERN),
+ Istituto Nazionale di Fisica Nucleare (INFN), Italy
+ Datamat Spa, Italy
+ Centre National de la Recherche Scientifique (CNRS), France
+ CS Systeme d'Information (CSSI), France
+ Royal Institute of Technology, Center for Parallel Computers (KTH-PDC), Sweden
+ Universiteit van Amsterdam (UvA), Netherlands
+ University of Helsinki (UH.HIP), Finland
+ University of Bergen (UiB), Norway
+ Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom
+
+ Common build properties file for the Glite WMS Common component
+
+ Authors: Alberto Di Meglio <alberto.di.meglio@cern.ch>
+ Joachim Flammer <Joachim.Flammer@cern.ch>
+ Version info: $Id$
+ Release: $Name$
+
+ Revision history:
+ $Log$
+
+-->
+
+<project name="WMS jobid component common properties">
+
+ <!-- Include build properties to allow overwriting
+ of properties for subsystem -->
+ <property file="build.properties" />
+
+ <!-- ======================================================
+ Define corresponding subsystem properties
+ ====================================================== -->
+
+ <!-- Subsystem name -->
+ <property name="subsystem.name" value="${wms.subsystem.name}"/>
+
+ <!-- Subsystem prefix -->
+ <property name="subsystem.prefix" value="${wms.subsystem.prefix}"/>
+
+ <!-- ======================================================
+ Define component properties
+ ====================================================== -->
+
+ <!-- Component name prefix -->
+ <property name="component.prefix" value="jobid" />
+
+ <!-- ======================================================
+ Define general component properties
+ ====================================================== -->
+
+ <import file="${component.general.properties.file}" />
+
+ <!-- ======================================================
+ Define extra properties here ...
+ ====================================================== -->
+
+
+</project>
--- /dev/null
+module.version=0.0.0
+module.build=0
+module.age=0
\ No newline at end of file
--- /dev/null
+## *********************************************************************
+## *
+## * Copyright (c) 2002 CERN and INFN on behalf of the EU DataGrid.
+## * For license conditions see LICENSE file or
+## * http://www.edg.org/license.html
+## *
+## *********************************************************************
+
+## Subdirectories list
+SUBDIRS = jobid
+
+jobid_includedir = $(includedir)/glite/workload/jobid
+jobid_include_HEADERS = jobid_namespace.h
+
+MAINTAINERCLEANFILES = Makefile.in
--- /dev/null
+/* **************************************************************************
+ * filename : JobId.cpp
+ * author : Alessandro Maraschini <alessandro.maraschini@datamat.it>
+ * copyright : (C) 2002 by DATAMAT
+ ***************************************************************************/
+
+#include "../jobid/JobId.h"
+#include <iostream>
+#include "../jobid/JobIdExceptions.h"
+
+
+COMMON_NAMESPACE_BEGIN{
+namespace jobid{
+using namespace std ;
+
+/******************************************************************
+ Constructor / Destructor
+ *******************************************************************/
+JobId::JobId() : m_JobId( 0 ), m_pStr( 0 ), m_pBkserver( 0 ), m_pUnique( 0 )
+{
+}
+
+JobId::JobId(const std::string& job_id_string )
+ : m_JobId( 0 ), m_pStr( 0 ), m_pBkserver( 0 ), m_pUnique( 0 )
+{
+ fromString( job_id_string ) ;
+}
+
+JobId::JobId(const JobId &old)
+{
+ edg_wlc_JobIdDup(old.m_JobId,&m_JobId);
+ m_pStr = old.m_pStr ? strdup(old.m_pStr) : 0;
+ m_pBkserver = old.m_pBkserver ? strdup(old.m_pBkserver) : 0;
+ m_pUnique = old.m_pUnique ? strdup(old.m_pUnique) : 0;
+}
+
+JobId & JobId::operator=(JobId const &old)
+{
+ clear();
+ edg_wlc_JobIdDup(old.m_JobId,&m_JobId);
+ m_pStr = old.m_pStr ? strdup(old.m_pStr) : 0;
+ m_pBkserver = old.m_pBkserver ? strdup(old.m_pBkserver) : 0;
+ m_pUnique = old.m_pUnique ? strdup(old.m_pUnique) : 0;
+
+ return *this;
+}
+
+
+JobId::JobId(const edg_wlc_JobId &old)
+ : m_pStr(0), m_pBkserver(0), m_pUnique(0)
+{
+ edg_wlc_JobIdDup(old,&m_JobId);
+}
+
+
+JobId & JobId::operator=(const edg_wlc_JobId &old)
+{
+ clear();
+ edg_wlc_JobIdDup(old,&m_JobId);
+ m_pStr = 0;
+ m_pBkserver = 0;
+ m_pUnique = 0;
+ return(*this);
+}
+
+JobId::~JobId()
+{
+ clear();
+}
+
+/******************************************************************
+ method : clear
+ unsets the JobId instance.
+ *******************************************************************/
+void JobId::clear()
+{
+ if ( m_JobId )
+ {
+ edg_wlc_JobIdFree( m_JobId );
+ m_JobId = 0;
+ if (m_pStr)
+ free(m_pStr);
+ if (m_pBkserver)
+ free(m_pBkserver);
+ if (m_pUnique)
+ free(m_pUnique);
+ m_pStr = m_pBkserver = m_pUnique = NULL;
+ }
+}
+
+
+/******************************************************************
+ method : setJobId
+ sets the JobId instance according to the LB and RB
+ server addresses and the unique string passed as input parameters.
+ *******************************************************************/
+void JobId::setJobId(const string& bkserver, int port, const string& unique)
+{
+ int code = edg_wlc_JobIdRecreate(bkserver.c_str(), port, unique.size() ? unique.c_str() : NULL, &m_JobId) ;
+ if ( code != 0 )
+ throw WrongIdException(__FILE__ , __LINE__ , "setJobId(const string& bkserver, int port, const string& unique)" , code ) ;
+}
+
+
+/******************************************************************
+ Protected method : fromString
+ sets the JobId instance from the dg_jobId in string format given as input.
+ *******************************************************************/
+void JobId::fromString (const string& dg_JobId)
+{
+ clear();
+ int code = edg_wlc_JobIdParse(dg_JobId.c_str(), &m_JobId) ;
+ if ( code != 0 )
+ throw WrongIdException(__FILE__ , __LINE__ , "fromString (const string& dg_JobId)" , code ) ;
+}
+
+/******************************************************************
+ method : ToString
+ converts the JobId instance into its string format.
+ and put it in the dg_jobId output variable
+ *******************************************************************/
+std::string JobId::toString() const
+{
+ if ( m_JobId && !m_pStr )
+ m_pStr = edg_wlc_JobIdUnparse(m_JobId) ;
+ if ( !m_pStr )
+ throw EmptyIdException (__FILE__ , __LINE__ ,"toString()" ,ENOENT , "JobId") ;
+ return m_pStr;
+}
+
+/******************************************************************
+ method : getServer
+ return a string containing the LB server address,
+ *******************************************************************/
+std::string JobId::getServer() const
+{
+ if ( m_JobId && !m_pBkserver )
+ m_pBkserver = edg_wlc_JobIdGetServer( m_JobId ) ;
+
+ if ( !m_pBkserver )
+ throw EmptyIdException (__FILE__ , __LINE__ , "getServer()", ENOENT , "LB server Address") ;
+
+ return m_pBkserver;
+}
+
+/******************************************************************
+ method : getUnique
+ return a string containing unique jobid string
+ *******************************************************************/
+std::string JobId::getUnique() const
+{
+ if ( m_JobId && !m_pUnique )
+ m_pUnique = edg_wlc_JobIdGetUnique( m_JobId ) ;
+
+ if ( !m_pUnique )
+ throw EmptyIdException (__FILE__ , __LINE__ , "getUnique()" , ENOENT , "Unique") ;
+
+ return m_pUnique;
+}
+/******************************************************************
+ method : getId
+ return the c JobId struct representing this instance
+ *******************************************************************/
+edg_wlc_JobId JobId::getId() const
+{
+ edg_wlc_JobId out ;
+ if ( edg_wlc_JobIdDup(m_JobId, &out) )
+ throw EmptyIdException (__FILE__ , __LINE__ , "getId()" , ENOENT , "JobId") ;
+ return out ;
+}
+
+std::ostream&
+operator<<(std::ostream& os, JobId const& id)
+{
+ return os << id.toString();
+}
+
+} COMMON_NAMESPACE_END}
--- /dev/null
+#ifndef EDG_WORKLOAD_COMMON_CLIENT_JOBID_H
+#define EDG_WORKLOAD_COMMON_CLIENT_JOBID_H
+
+/*
+ * JobId.h
+ * Copyright (c) 2001 The European Datagrid Project - IST programme, all rights reserved.
+ *
+ */
+
+#include <string>
+#include <iosfwd>
+
+#include "../jobid_namespace.h"
+#include "../jobid/jobid-c.h"
+
+typedef struct _edg_wlc_jobid_s* edg_wlc_jobid_t;
+
+#define COMMON_JOBID_NAMESPACE_BEGIN namespace edg { namespace workload { namespace common {namespace jobid{
+COMMON_JOBID_NAMESPACE_BEGIN
+/**
+ * Managing Identification, checking, retreiving info from a job
+ * File name: JobId.h
+ * The JobId class provides a representation of the Datagrid job identifier
+ * (dg_jobId) and the methods for manipulating it.
+ * We remind that the format of the dg_jobId is as follows:
+ * <LB address>:<LB port>/<Unique String>
+ *
+ * @ingroup common
+ * @version 0.1
+ * @date 15 April 2002
+ * @author Alessandro Maraschini <alessandro.maraschini@datamat.it> */
+ class JobId {
+public:
+ /**@name Constructors/Destructor */
+ //@{
+ /** Instantiates an empty JobId object */
+ JobId() ;
+ /**
+ * Instantiates a JobId object from the passed dg_jobId in string format.
+ * @param job_id_string a string representig a classAd expression
+ * @throws WrongIdException When a string is passed in a wrong format
+ */
+ JobId(const std::string& job_id_string ) ;
+ JobId(const JobId&);
+ JobId(const edg_wlc_JobId&);
+ /**
+ * Destructor
+ * Destroy the Job Id instance
+ */
+ ~JobId() ;
+ //@}
+
+ /**@name Miscellaneous */
+ //@{
+ /** Unsets the JobId instance. Clear all it's memebers */
+ void clear() ;
+ /**
+ * Check wheater the jobId has been already created (true) or not (false)
+ *@return true (jobId created) or false (jobId not yet created)
+ */
+ bool isSet() { return ( m_JobId != 0 ) ; }
+ /**
+ * Set the JobId instance according to the LB and RB server addresses and the unique string passed as input parameters.
+ * @param lb_server Loggin and Bookkeeping server address
+ * @param port Loggin and Bookkeeping port ( dafault value is 9000 )
+ * @param unique A Unique identification ( automatically generatad by md5 protocol )
+ * @throws WrongIdException When one parameter has been passed in a wrong format */
+ void setJobId(const std::string& lb_server, int port = 0, const std::string& unique = "");
+ //@}
+ /**@name Get Methods */
+ //@{
+ /** @return the LB address into its string format
+ * @throws EmptyIdException If the jobId has not been initialised yet */
+ std::string getServer() const;
+ /** @return the Unique string into its string format
+ * @throws EmptyIdException If the jobId has not been initialised yet */
+ std::string getUnique() const;
+ //@}
+ /** This method sets the JobId instance from the JobId in string format given
+ * as input.
+ * @param dg_JobId the string representing the job
+ * @throws WrongIdException When a string is passed in a wrong format */
+ void fromString ( const std::string& dg_JobId );
+ /** Converts the jobId into a string
+ @return the string representation of a JobId*/
+ std::string toString() const;
+ operator const edg_wlc_JobId() const { return m_JobId; }
+ JobId & operator=(JobId const &);
+ JobId & operator=(const edg_wlc_JobId &);
+ edg_wlc_JobId getId() const ;
+private:
+ // This Variable stores the Job unique identification String
+ edg_wlc_JobId m_JobId;
+ mutable char* m_pStr;
+ mutable char* m_pBkserver;
+ mutable char* m_pUnique;
+
+ friend bool operator<(JobId const& lhs, JobId const& rhs);
+ friend bool operator==(JobId const& lhs, JobId const& rhs);
+};
+
+inline bool operator<(JobId const& lhs, JobId const& rhs)
+{
+ return strcmp ( lhs.m_pStr , rhs.m_pStr ) <0 ;
+}
+
+inline bool operator==(JobId const& lhs, JobId const& rhs)
+{
+return strcmp ( lhs.m_pStr , rhs.m_pStr ) ==0 ;
+}
+
+std::ostream& operator<<(std::ostream& os, JobId const& id);
+
+} COMMON_NAMESPACE_END }
+
+#endif // EDG_WORKLOAD_COMMON_CLIENT_JOBID_H
--- /dev/null
+/* **************************************************************************
+* filename : JobIdExecptions.cpp
+* author : Alessandro Maraschini <alessandro.maraschini@datamat.it>
+* copyright : (C) 2002 by DATAMAT
+***************************************************************************/
+#include "../jobid/JobIdExceptions.h"
+
+COMMON_NAMESPACE_BEGIN{
+namespace jobid{
+using namespace std ;
+using namespace edg::workload::common::utilities ;
+/*****************************
+* JobIdException
+*****************************/
+JobIdException::JobIdException (const string& file,
+ int line,
+ const string& method,
+ int code,
+ const string& exception_name)
+ : Exception(file, line, method, code, exception_name){}
+/*****************************
+* WrongIdException
+*****************************/
+WrongIdException::WrongIdException(const string& file,
+ int line,
+ const string& method,
+ int code )
+ : JobIdException(file, line, method, code,
+ "WrongIdException"){
+ error_message = "Wrong Field caught while parsing Job Id" ;
+ };
+/*****************************
+* EmptyIdException
+*****************************/
+EmptyIdException::EmptyIdException(const string& file,
+ int line,
+ const string& method,
+ int code ,
+ const string& field )
+ : JobIdException(file, line, method, code,
+ "EmptyIdException")
+ {
+ error_message = "Unable to retrieve " + field + ": the instance has not been initialized yet";
+ }
+
+} COMMON_NAMESPACE_END }
+
--- /dev/null
+#ifndef EDG_WORKLOAD_COMMON_CLIENT_JOBIDEXCEPTIONS_H
+#define EDG_WORKLOAD_COMMON_CLIENT_JOBIDEXCEPTIONS_H
+
+/*
+ * JobIdExceptions.h
+ * Copyright (c) 2001 The European Datagrid Project - IST programme, all rights reserved.
+ */
+#include "glite/workload/common/utilities/Exceptions.h"
+
+#define COMMON_JOBID_NAMESPACE_BEGIN namespace edg { namespace workload { namespace common {namespace jobid{
+COMMON_JOBID_NAMESPACE_BEGIN
+/**
+ * JobIdException - Exception thrown by JobId Class
+ * @ingroup Common
+ * @version 0.1
+ * @date 15 April 2002
+ * @author Alessandro Maraschini <alessandro.maraschini@datamat.it>
+*/
+class JobIdException : public edg::workload::common::utilities::Exception {
+public:
+ /**
+ * Update all mandatory Exception Information
+ */
+ JobIdException (const std::string& file,
+ int line,
+ const std::string& method,
+ int code,
+ const std::string& exception_name) ;
+};//End CLass JobIdException
+
+/**
+* WrongIdFieldException
+* This Exception is thrown when a Job Id syntax error is found
+* A valid Job Identification string should be made as follows:
+* <LB address>:<LB port>/ <Unique string> */
+class WrongIdException : public JobIdException {
+public:
+ /**
+ * Constructor
+ * @param file - The source file which has generated the Exception
+ * @param line - The line number in the source file where the Exception has been thrown
+ * @param method - The Name of the method which has thrown the Exception
+ * @param code - The Code of the Error raised
+ * @param field - The wrong expression catched */
+ WrongIdException(const std::string& file,
+ int line,
+ const std::string& method,
+ int code );
+}; //End CLass WrongIdException
+/**
+* EmptyIdException
+* This Exception is thrown when the user tries to get information from a JobId
+* which has not been initialized yet, i.e tries to use the get<field name> Methods
+*/
+class EmptyIdException : public JobIdException {
+public:
+ /**
+ * Constructor
+ * @param file - The source file which has generated the Exception
+ * @param line - The line number in the source file where the Exception has been thrown
+ * @param method - The Name of the method which has thrown the Exception
+ * @param code - The Code of the Error raised
+ * @param field - The Empty filed requested for */
+ EmptyIdException::EmptyIdException(const std::string& file,
+ int line,
+ const std::string& method,
+ int code ,
+ const std::string& field );
+}; //End CLass EmptyIdException
+} COMMON_NAMESPACE_END }
+#endif
+
--- /dev/null
+## *********************************************************************
+## *
+## * Copyright (c) 2002 CERN and INFN on behalf of the EU DataGrid.
+## * For license conditions see LICENSE file or
+## * http://www.edg.org/license.html
+## *
+## *********************************************************************
+
+lib_LTLIBRARIES = libglite_wl_jobid.la
+
+libglite_wl_jobid_la_SOURCES = \
+ JobId.cpp \
+ JobIdExceptions.cpp \
+ manipulation.cpp \
+ jobid.c \
+ strmd5.c
+
+jobidincludedir = $(includedir)/glite/workload/jobid
+jobidinclude_HEADERS = \
+ JobId.h \
+ JobIdExceptions.h \
+ jobid-c.h \
+ manipulation.h \
+ strmd5.h
+
+AM_CPPFLAGS = -I$(top_srcdir)/.. \
+ $(GLOBUS_CFLAGS) $(BOOST_CFLAGS) \
+ $(GLITE_WORKLOAD_CFLAGS) \
+ -D_GNU_SOURCE
+
+MAINTAINERCLEANFILES = Makefile.in
--- /dev/null
+#ifndef _EDG_JOBID_H
+#define _EDG_JOBID_H
+
+/*!
+ * \file common/jobid/jobid-c.h
+ * \brief L&B consumer API
+ */
+
+#ident "$Header$"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct _edg_wlc_JobId *edg_wlc_JobId;
+
+#define EDG_WLC_JOBID_DEFAULT_PORT 9000 /**< Default port where bookkeeping server listens */
+#define EDG_WLC_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 edg_wlc_JobIdCreate(const char * bkserver, int port, edg_wlc_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 edg_wlc_JobIdRecreate(const char *bkserver, int port, const char * unique, edg_wlc_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 edg_wlc_JobIdDup(const edg_wlc_JobId in, edg_wlc_JobId * jobid);
+
+/*
+ * Free jobid structure
+ * \param jobid for dealocation
+ */
+void edg_wlc_JobIdFree(edg_wlc_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 edg_wlc_JobIdParse(const char* jobidstr, edg_wlc_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* edg_wlc_JobIdUnparse(const edg_wlc_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* edg_wlc_JobIdGetServer(const edg_wlc_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 edg_wlc_JobIdGetServerParts(const edg_wlc_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* edg_wlc_JobIdGetUnique(const edg_wlc_JobId jobid);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _EDG_JOBID_H */
--- /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 "../jobid/jobid-c.h"
+#include "../jobid/strmd5.h"
+
+struct _edg_wlc_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 edg_wlc_JobIdCreate(const char *bkserver, int port, edg_wlc_JobId *jobId)
+{
+ return edg_wlc_JobIdRecreate(bkserver, port, NULL, jobId);
+}
+
+
+int edg_wlc_JobIdRecreate(const char* bkserver, int port, const char *unique, edg_wlc_JobId *jobId)
+{
+ edg_wlc_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;
+
+ 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 = (edg_wlc_JobId) malloc (sizeof(*out));
+ if (!out)
+ return ENOMEM;
+
+ memset(out, 0, sizeof(*out));
+
+ /* check if it begins with prefix */
+ /* unsupported */
+ if (strncmp(bkserver, EDG_WLC_JOBID_PROTO_PREFIX, sizeof(EDG_WLC_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 = EDG_WLC_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) {
+ edg_wlc_JobIdFree(out);
+ return ENOMEM;
+ }
+
+ *jobId = out;
+ return 0;
+}
+
+
+int edg_wlc_JobIdDup(const edg_wlc_JobId in, edg_wlc_JobId *out)
+{
+ edg_wlc_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) {
+ edg_wlc_JobIdFree(jid);
+ return ENOMEM;
+ }
+
+ jid->BSport = in->BSport;
+ *out = jid;
+ return 0;
+}
+
+
+// XXX
+// use recreate
+// parse name, port, unique
+int edg_wlc_JobIdParse(const char *idString, edg_wlc_JobId *jobId)
+{
+ char *pom, *pom1, *pom2;
+ edg_wlc_JobId out;
+
+ *jobId = NULL;
+
+ out = (edg_wlc_JobId) malloc (sizeof(*out));
+ if (out == NULL )
+ return ENOMEM;
+
+ memset(out,0,sizeof(*out));
+
+ if (strncmp(idString, EDG_WLC_JOBID_PROTO_PREFIX, sizeof(EDG_WLC_JOBID_PROTO_PREFIX) - 1)) {
+ out->BShost = (char *) NULL;
+ out->BSport = 0;
+
+ free(out);
+ return EINVAL;
+ }
+
+ pom = strdup(idString + sizeof(EDG_WLC_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 = EDG_WLC_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);
+
+ free(pom);
+ *jobId = out;
+ return 0;
+}
+
+
+void edg_wlc_JobIdFree(edg_wlc_JobId job)
+{
+ if (job) {
+ free(job->id);
+ free(job->BShost);
+ free(job->info);
+ free(job);
+ }
+}
+
+
+char* edg_wlc_JobIdUnparse(const edg_wlc_JobId jobid)
+{
+ char *out, port[40];
+
+ if (!jobid)
+ return NULL;
+
+ if (jobid->BSport)
+ sprintf(port,":%d",jobid->BSport);
+ else
+ *port = 0;
+
+ asprintf(&out,EDG_WLC_JOBID_PROTO_PREFIX"%s%s/%s%s%s",
+ jobid->BShost,port,
+ jobid->id,
+ (jobid->info ? "?" : ""),
+ (jobid->info ? jobid->info : ""));
+
+ return out;
+}
+
+
+char* edg_wlc_JobIdGetServer(const edg_wlc_JobId jobid)
+{
+ char *bs = NULL;
+
+ if (jobid)
+ asprintf(&bs, "%s:%u", jobid->BShost,
+ jobid->BSport ? jobid->BSport : EDG_WLC_JOBID_DEFAULT_PORT);
+
+ return bs;
+}
+
+
+void edg_wlc_JobIdGetServerParts(const edg_wlc_JobId jobid, char **srvName, unsigned int *srvPort)
+{
+ if (jobid) {
+ *srvName = strdup(jobid->BShost);
+ *srvPort = jobid->BSport ? jobid->BSport : EDG_WLC_JOBID_DEFAULT_PORT;
+ }
+}
+
+
+char* edg_wlc_JobIdGetUnique(const edg_wlc_JobId jobid)
+{
+ return jobid ? strdup(jobid->id) : NULL;
+}
--- /dev/null
+#include <cctype>
+
+#include <string>
+#include <algorithm>
+
+#include "../jobid_namespace.h"
+#include "../jobid/JobId.h"
+
+using namespace std;
+
+COMMON_NAMESPACE_BEGIN {
+
+namespace jobid {
+
+namespace {
+
+class HexInt {
+public:
+ HexInt( unsigned int i = 0 );
+ HexInt( const string &str );
+ HexInt( string::const_iterator begin, string::const_iterator end );
+ ~HexInt( void );
+
+ inline operator unsigned int( void ) const { return this->hi_int; }
+ inline operator const string &( void ) const { return this->hi_str; }
+
+ static unsigned int least( void ) { return hi_s_least; }
+ static void least( unsigned int least ) { hi_s_least = least; }
+
+private:
+ void parseString( void );
+
+ unsigned int hi_int;
+ string hi_str;
+
+ static unsigned int hi_s_least;
+ static const char *hi_s_map;
+};
+
+class BadChar {
+public:
+ BadChar( void );
+ ~BadChar( void );
+
+ inline bool operator()( char c )
+ { return( !(((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || ((c >= '0') && (c <= '9')) ||
+ (c == '.') || (c == '-') || (c == ' ')) ); }
+};
+
+unsigned int HexInt::hi_s_least = 2;
+const char *HexInt::hi_s_map = "0123456789abcdef";
+
+HexInt::HexInt( unsigned int ui ) : hi_int( ui ), hi_str( hi_s_least, '0' )
+{
+ int n;
+ string::reverse_iterator pos = this->hi_str.rbegin();
+
+ while( ui != 0 ) {
+ n = ui % 16;
+ if( pos != this->hi_str.rend() ) {
+ *pos = hi_s_map[n];
+ pos += 1;
+ }
+ else this->hi_str.insert( this->hi_str.begin(), hi_s_map[n] );
+
+ ui /= 16;
+ }
+
+ if( this->hi_str.length() < hi_s_least )
+ this->hi_str.insert( this->hi_str.begin(), (hi_s_least - this->hi_str.length()), '0' );
+}
+
+HexInt::HexInt( const string &str ) : hi_int( 0 ), hi_str( str )
+{
+ this->parseString();
+}
+
+HexInt::HexInt( string::const_iterator begin, string::const_iterator end ) : hi_int( 0 ), hi_str( begin, end )
+{
+ this->parseString();
+}
+
+void HexInt::parseString( void )
+{
+ int hexbase;
+ char *pos, *end = (char *) hi_s_map + 16;
+ string::reverse_iterator it;
+
+ for( it = this->hi_str.rbegin(), hexbase = 1; it != this->hi_str.rend(); ++it, hexbase *= 16 ) {
+ pos = find( (char *) hi_s_map, end, (char) tolower(*it) );
+
+ if( pos != end ) this->hi_int += hexbase * (pos - hi_s_map);
+ else {
+ this->hi_int = 0;
+ break;
+ }
+ }
+
+ return;
+}
+
+HexInt::~HexInt( void ) {}
+
+BadChar::BadChar( void ) {}
+
+BadChar::~BadChar( void ) {}
+
+/*
+ Helper function for the get_reduced_part(...)
+*/
+string get_reduced_part_internal( const string &unique, int level )
+{
+ string::size_type length = unique.length();
+ string piece( unique.substr(0, 2) ), answer;
+
+ if( (level == 0) || (length <= 2) ) answer.assign( piece );
+ else if( length != 0 ) {
+ answer.assign( piece );
+ answer.append( 1, '/' );
+ answer.append( get_reduced_part_internal(unique.substr(2, length - 2), level - 1) );
+ }
+
+ return answer;
+}
+
+}; // Unnamed namespace
+
+string get_reduced_part( const JobId &id, int level )
+{
+ return get_reduced_part_internal( id.getUnique(), level );
+}
+
+string to_filename( const JobId &id )
+{
+ string sid( id.toString() ), coded;
+ string::iterator last, next;
+
+ last = sid.begin();
+ do {
+ next = find_if( last, sid.end(), BadChar() );
+
+ if( next != sid.end() ) {
+ if( last != next ) coded.append( last, next );
+ coded.append( 1, '_' );
+ coded.append( HexInt(*next) );
+
+ last = next + 1;
+ }
+ else coded.append( last, sid.end() );
+ } while( next != sid.end() );
+
+ return coded;
+}
+
+JobId from_filename( const string &filename )
+{
+ char c;
+ string decoded;
+ string::const_iterator last, next;
+
+ last = filename.begin();
+ do {
+ next = find( last, filename.end(), '_' );
+
+ if( next != filename.end() ) {
+ c = HexInt( next + 1, next + 3 );
+
+ if( last != next ) decoded.append( last, next );
+ decoded.append( 1, c );
+
+ last = next + 3;
+ }
+ else decoded.append( last, filename.end() );
+ } while( next != filename.end() );
+
+ return JobId( decoded );
+}
+
+}; // Namespace jobid
+
+} COMMON_NAMESPACE_END;
--- /dev/null
+#ifndef EDG_WORKLOAD_COMMON_JOBID_MANIPULATION_H
+#define EDG_WORKLOAD_COMMON_JOBID_MANIPULATION_H
+
+#include <string>
+
+#include "../common_namespace.h"
+
+COMMON_NAMESPACE_BEGIN {
+
+namespace jobid {
+
+class JobId;
+
+std::string get_reduced_part( const JobId &id, int level = 0 );
+std::string to_filename( const JobId &id );
+JobId from_filename( const std::string &filename );
+
+}; // Namespace jobid
+
+} COMMON_NAMESPACE_END;
+
+#endif /* EDG_WORKLOAD_COMMON_JOBID_MANIPULATION_H */
+
+// Local Variables:
+// mode: c++
+// End:
--- /dev/null
+#ident "$Header$"
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <openssl/md5.h>
+
+#include "../jobid/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);
+}
--- /dev/null
+#ifndef _EDG_STRMD5_H
+#define _EDG_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 /* _EDG_STRMD5_H */
--- /dev/null
+#ifndef __COMMON_NAMESPACE_H_LOADED
+#define __COMMON_NAMESPACE_H_LOADED
+
+#define COMMON_NAMESPACE_BEGIN namespace edg { namespace workload { namespace common
+
+#define COMMON_NAMESPACE_END }}
+
+#define USING_COMMON_NAMESPACE using namespace edg::workload::common
+#define USING_COMMON_NAMESPACE_ADD( last ) using namespace edg::workload::common::##last
+
+#define COMMON_NAMESPACE_CLASS( Type ) \
+namespace edg { namespace workload { namespace common { \
+ class Type; \
+}}}
+
+#define COMMON_SUBNAMESPACE_CLASS( Namespace, Type ) \
+namespace edg { namespace workload { namespace common { \
+ namespace Namespace { \
+ class Type; \
+ } \
+}}}
+
+#endif /* __COMMON_NAMESPACE_H_LOADED */
+
+// Local Variables:
+// mode: c++
+// End:
--- /dev/null
+## *********************************************************************
+## *
+## * Copyright (c) 2002 CERN and INFN on behalf of the EU DataGrid.
+## * For license conditions see LICENSE file or
+## * http://www.edg.org/license.html
+## *
+## *********************************************************************
+
+STDCPP = -lstdc++
+
+WL_JOBID_TEST = testjobid
+
+check_PROGRAMS = $(WL_JOBID_TEST)
+
+testjobid_SOURCES = testjobid.c
+testjobid_LDADD = \
+ $(top_builddir)/src/jobid/libglite_wl_jobid.la \
+ $(GLITE_WORKLOAD_COMMON_LIBS) \
+ $(GLOBUS_LIBS) \
+ $(STDCPP)
+
+AM_CPPFLAGS = -I$(top_srcdir)/src \
+ $(BOOST_CFLAGS) \
+ $(CLASSAD_CFLAGS) \
+ $(GLITE_WORKLOAD_COMMON_CFLAGS) \
+ $(GLOBUS_CFLAGS)
+
+MAINTAINERCLEANFILES = Makefile.in *~
+
--- /dev/null
+/* test code for jobid routines */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "../src/jobid/jobid-c.h"
+
+int main(int argc, char* argv[])
+{
+ char* ju;
+ char* bkserver = "ujsa.uhjs";
+ edg_wlc_JobId ji = 0;
+ edg_wlc_JobId ji2 = 0;
+ int r = edg_wlc_JobIdCreate(bkserver, 0, &ji);
+ printf("Create: %d\n", r);
+
+ ju = edg_wlc_JobIdUnparse(ji);
+ printf("Unparse: %s\n", ju);
+
+ edg_wlc_JobIdParse(ju, &ji2);
+ free(ju);
+
+ ju = edg_wlc_JobIdUnparse(ji);
+ printf("Unparse2: %s\n", ju);
+ free(ju);
+
+ edg_wlc_JobIdFree(ji);
+ edg_wlc_JobIdFree(ji2);
+ return 0;
+}