RPM Package Manager, CVS Repository http://rpm5.org/cvs/ ____________________________________________________________________________
Server: rpm5.org Name: Ralf S. Engelschall Root: /v/rpm/cvs Email: [EMAIL PROTECTED] Module: rpm Date: 01-Feb-2008 14:48:47 Branch: HEAD Handle: 2008020113484601 Added files: rpm/rpmio rpmuuid.c rpmuuid.h Modified files: rpm CHANGES rpm/rpmio Makefile.am librpmio.vers Log: Add new C API function rpmuuidMake() for easily generating UUIDs of version 1 (node and time based), 3 (MD5 hash based), 4 (random data based) or 5 (SHA1 hash bashed). This in the next step will be use from within RPM when having to generate UUIDs for various purposes. Summary: Revision Changes Path 1.2121 +1 -0 rpm/CHANGES 1.119 +2 -2 rpm/rpmio/Makefile.am 2.33 +1 -0 rpm/rpmio/librpmio.vers 2.1 +112 -0 rpm/rpmio/rpmuuid.c 2.1 +25 -0 rpm/rpmio/rpmuuid.h ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/CHANGES ============================================================================ $ cvs diff -u -r1.2120 -r1.2121 CHANGES --- rpm/CHANGES 1 Feb 2008 07:59:58 -0000 1.2120 +++ rpm/CHANGES 1 Feb 2008 13:48:46 -0000 1.2121 @@ -1,4 +1,5 @@ 5.0.0 -> 5.1a1: + - rse: add new C API function rpmuuidMake() for generating UUIDs of version 1, 3, 4 or 5 - rse: provide both ORIGINTIME (based on INSTALLTIME) and ORIGINTID (based on INSTALLTID) - jbj: pedantic identification of Foo (not foo) syscalls in --fsmdebug spew. - jbj: fix: --rollback PSM_INIT changes added fstates before initialize. @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/Makefile.am ============================================================================ $ cvs diff -u -r1.118 -r1.119 Makefile.am --- rpm/rpmio/Makefile.am 18 Dec 2007 19:40:54 -0000 1.118 +++ rpm/rpmio/Makefile.am 1 Feb 2008 13:48:47 -0000 1.119 @@ -34,7 +34,7 @@ pkginc_HEADERS = \ argv.h envvar.h fts.h mire.h rpmbc.h rpmcb.h rpmdav.h rpmhash.h \ rpmio.h rpmio-stub.h rpmlog.h rpmmacro.h rpmmg.h rpmnss.h rpmpgp.h \ - rpmsq.h rpmssl.h rpmsw.h rpmurl.h rpmxar.h stringbuf.h ugid.h + rpmsq.h rpmssl.h rpmsw.h rpmurl.h rpmxar.h stringbuf.h ugid.h rpmuuid.h noinst_HEADERS = \ md2.h md4.h rmd128.h rmd160.h rmd256.h rmd320.h sha224.h \ salsa10.h salsa20.h tiger.h \ @@ -49,7 +49,7 @@ rpmbc.c rpmdav.c rpmhash.c rpmhook.c rpmio.c rpmio-stub.c \ rpmlog.c rpmlua.c rpmmalloc.c rpmmg.c rpmnss.c rpmpgp.c \ rpmrpc.c rpmsq.c rpmssl.c rpmsw.c rpmxar.c \ - strcasecmp.c stringbuf.c strtolocale.c url.c ugid.c + strcasecmp.c stringbuf.c strtolocale.c url.c ugid.c rpmuuid.c librpmio_la_LDFLAGS = -release $(LT_CURRENT).$(LT_REVISION) if HAVE_LD_VERSION_SCRIPT librpmio_la_LDFLAGS += -Wl,--version-script=$(srcdir)/librpmio.vers @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/librpmio.vers ============================================================================ $ cvs diff -u -r2.32 -r2.33 librpmio.vers --- rpm/rpmio/librpmio.vers 2 Jan 2008 19:10:14 -0000 2.32 +++ rpm/rpmio/librpmio.vers 1 Feb 2008 13:48:47 -0000 2.33 @@ -320,6 +320,7 @@ rpmxarPull; rpmxarSwapBuf; XrpmxarUnlink; + rpmuuidMake; Stat; _Stat; stripTrailingBlanksStringBuf; @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmuuid.c ============================================================================ $ cvs diff -u -r0 -r2.1 rpmuuid.c --- /dev/null 2008-02-01 14:44:00 +0100 +++ rpmuuid.c 2008-02-01 14:48:47 +0100 @@ -0,0 +1,112 @@ +/** \ingroup rpmio + * \file rpmio/rpmuuid.c + */ + +#include "system.h" +#include <string.h> +#include "rpmlog.h" +#include "rpmuuid.h" +#ifdef WITH_UUID +#include "uuid.h" +#endif +#include "debug.h" + +int rpmuuidMake(int version, const char *ns, const char *data, char *buf_str, unsigned char *buf_bin) +{ +#ifdef WITH_UUID + uuid_rc_t rc; + uuid_t *uuid = NULL; + uuid_t *uuid_ns = NULL; + char *result_ptr; + size_t result_len; + + /* sanity check version */ + if (!(version == 1 || (version >= 3 && version <= 5))) { + rpmlog(RPMLOG_ERR, "invalid UUID version number"); + return 1; + } + if ((version == 3 || version == 5) && (ns == NULL || data == NULL)) { + rpmlog(RPMLOG_ERR, "namespace or data required for requested UUID version\n"); + return 1; + } + if (buf_str == NULL && buf_bin == NULL) { + rpmlog(RPMLOG_ERR, "either string or binary result buffer required\n"); + return 1; + } + + /* create UUID object */ + if ((rc = uuid_create(&uuid)) != UUID_RC_OK) { + rpmlog(RPMLOG_ERR, "failed to create UUID object: %s\n", uuid_error(rc)); + return 1; + } + + /* create optional UUID namespace object */ + if (version == 3 || version == 5) { + if ((rc = uuid_create(&uuid_ns)) != UUID_RC_OK) { + rpmlog(RPMLOG_ERR, "failed to create UUID namespace object: %s\n", uuid_error(rc)); + return 1; + } + if ((rc = uuid_load(uuid_ns, ns)) != UUID_RC_OK) { + if ((rc = uuid_import(uuid_ns, UUID_FMT_STR, ns, strlen(ns))) != UUID_RC_OK) { + rpmlog(RPMLOG_ERR, "failed to import UUID namespace object: %s\n", uuid_error(rc)); + return 1; + } + } + } + + /* generate UUID */ + if (version == 1) + rc = uuid_make(uuid, UUID_MAKE_V1); + else if (version == 3) + rc = uuid_make(uuid, UUID_MAKE_V3, uuid_ns, data); + else if (version == 4) + rc = uuid_make(uuid, UUID_MAKE_V4); + else if (version == 5) + rc = uuid_make(uuid, UUID_MAKE_V3, uuid_ns, data); + if (rc != UUID_RC_OK) { + uuid_destroy(uuid); + if (uuid_ns != NULL) + uuid_destroy(uuid_ns); + rpmlog(RPMLOG_ERR, "failed to make UUID object: %s\n", uuid_error(rc)); + return 1; + } + + /* export UUID */ + if (buf_str != NULL) { + result_ptr = buf_str; + result_len = UUID_LEN_STR+1; + if ((rc = uuid_export(uuid, UUID_FMT_STR, &result_ptr, &result_len)) != UUID_RC_OK) { + uuid_destroy(uuid); + if (uuid_ns != NULL) + uuid_destroy(uuid_ns); + rpmlog(RPMLOG_ERR, "failed to export UUID object as string representation: %s\n", uuid_error(rc)); + return 1; + } + } + if (buf_bin != NULL) { + result_ptr = (char *)buf_bin; + result_len = UUID_LEN_BIN; + if ((rc = uuid_export(uuid, UUID_FMT_BIN, &result_ptr, &result_len)) != UUID_RC_OK) { + uuid_destroy(uuid); + if (uuid_ns != NULL) + uuid_destroy(uuid_ns); + rpmlog(RPMLOG_ERR, "failed to export UUID object as binary representation: %s\n", uuid_error(rc)); + return 1; + } + } + + /* destroy UUID object(s) */ + uuid_destroy(uuid); + if (uuid_ns != NULL) + uuid_destroy(uuid_ns); + + /* indicate success */ + return 0; +#else + rpmlog(RPMLOG_ERR, "UUID generator not available!\n"); + + /* indicate error */ + return 1; +#endif +} + @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmuuid.h ============================================================================ $ cvs diff -u -r0 -r2.1 rpmuuid.h --- /dev/null 2008-02-01 14:44:00 +0100 +++ rpmuuid.h 2008-02-01 14:48:47 +0100 @@ -0,0 +1,25 @@ +#ifndef _H_RPMUUID_ +#define _H_RPMUUID_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Generate a Universally Unique Identifier (UUID). + * @param version UUID version 1, 3, 4 or 5 + * @param ns namespace UUID in string representation or symbolic name (UUID version 3 and 5 only) + * @param data data to digest (UUID version 3 and 5 only) + * @retval buf_str buffer of at least 37 bytes (UUID_LEN_STR+1) to store UUID in string representation + * @retval buf_buf buffer of at least 16 bytes (UUID_LEN_BIN) to store UUID in binary representation + * @return 0 on success, 1 on failure + */ +int rpmuuidMake(int version, const char *ns, const char *data, + /[EMAIL PROTECTED]@*/ char *buf_str, /[EMAIL PROTECTED]@*/ unsigned char *buf_bin); + +#ifdef __cplusplus +} +#endif + +#endif /* _H_ RPMUUID_ */ + @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository rpm-cvs@rpm5.org