RPM Community Forums

Mailing List Message of <rpm-cvs>

[CVS] RPM: lua/ Makefile.am lua/local/ luuid.c luuid.h rpm/ CHANGES IN...

From: Ralf S. Engelschall <rse@rpm5.org>
Date: Thu 10 Jan 2008 - 21:49:36 CET
Message-Id: <20080110204936.D7226348460@rpm5.org>
  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Ralf S. Engelschall
  Root:   /v/rpm/cvs                       Email:  rse@rpm5.org
  Module: rpm lua                          Date:   10-Jan-2008 21:49:36
  Branch: HEAD                             Handle: 2008011020493501

  Added files:
    lua/local               luuid.c luuid.h
  Modified files:
    lua                     Makefile.am
    rpm                     CHANGES INSTALL configure.ac devtool.conf
    rpm/rpmio               rpmlua.c

  Log:
    Add OSSP uuid support to RPM Lua via the following Lua extension functions:
    
    1. <uuid> = uuid.generate(<version>[, <uuid-namespace>, <data>])
    2. <description> = uuid.describe(<uuid>)
    
    Examples:
    
    o time and node based UUID version 1:
    
      $ ./rpm --eval '%{lua: print(uuid.describe(uuid.generate(1))) }'
      encode: STR:     8bac0154-bfbb-11dc-b37a-0019d13dcdc5
              SIV:     185655793470684341891202606725542563269
      decode: variant: DCE 1.1, ISO/IEC 11578:1996
              version: 1 (time and node based)
              content: time:  2008-01-10 20:35:13.736738.0 UTC
                       clock: 13178 (usually random)
                       node:  00:19:d1:3d:cd:c5 (global unicast)
      $ ./rpm --eval '%{lua: print(uuid.describe(uuid.generate(1))) }'
      encode: STR:     8d458198-bfbb-11dc-9e16-0019d13dcdc5
              SIV:     187782044421769404773519444360879263173
      decode: variant: DCE 1.1, ISO/IEC 11578:1996
              version: 1 (time and node based)
              content: time:  2008-01-10 20:35:16.420444.0 UTC
                       clock: 7702 (usually random)
                       node:  00:19:d1:3d:cd:c5 (global unicast)
    
    o namespace and message digest based UUID version 3:
    
      $ ./rpm --eval '%{lua: print(uuid.describe(uuid.generate(3, "ns:URL", "http://rpm5.org/"))) }'
      encode: STR:     d74931ab-be1d-3b9f-8798-01a0fe9ce9e1
              SIV:     286164064209353816239503491618855250401
      decode: variant: DCE 1.1, ISO/IEC 11578:1996
              version: 3 (name based, MD5)
              content: D7:49:31:AB:BE:1D:0B:9F:07:98:01:A0:FE:9C:E9:E1
                       (not decipherable: MD5 message digest only)
      $ ./rpm --eval '%{lua: print(uuid.describe(uuid.generate(3, "ns:URL", "http://rpm5.org/"))) }'
      encode: STR:     d74931ab-be1d-3b9f-8798-01a0fe9ce9e1
              SIV:     286164064209353816239503491618855250401
      decode: variant: DCE 1.1, ISO/IEC 11578:1996
              version: 3 (name based, MD5)
              content: D7:49:31:AB:BE:1D:0B:9F:07:98:01:A0:FE:9C:E9:E1
    
    o random data based UUID version 4:
    
      $ ./rpm --eval '%{lua: print(uuid.describe(uuid.generate(4))) }'
      encode: STR:     ac320384-20a3-4d12-8d6f-414fee3c0ab9
              SIV:     228886901433379473546117410711676914361
      decode: variant: DCE 1.1, ISO/IEC 11578:1996
              version: 4 (random data based)
              content: AC:32:03:84:20:A3:0D:12:0D:6F:41:4F:EE:3C:0A:B9
                       (no semantics: random data only)
      $ ./rpm --eval '%{lua: print(uuid.describe(uuid.generate(4))) }'
      encode: STR:     144d3a75-0cc6-447d-8135-5684632a566c
              SIV:     26985552427211036017499201490289055340
      decode: variant: DCE 1.1, ISO/IEC 11578:1996
              version: 4 (random data based)
              content: 14:4D:3A:75:0C:C6:04:7D:01:35:56:84:63:2A:56:6C
                       (no semantics: random data only)
    
    OSSP uuid later can also be used for other purposes within RPM,
    for instance for PKGID, SOURCEPKID or similar things.

  Summary:
    Revision    Changes     Path
    1.16        +2  -0      lua/Makefile.am
    1.1         +156 -0     lua/local/luuid.c
    1.1         +7  -0      lua/local/luuid.h
    1.2058      +1  -0      rpm/CHANGES
    2.72        +1  -0      rpm/INSTALL
    2.271       +11 -0      rpm/configure.ac
    2.172       +22 -0      rpm/devtool.conf
    2.38        +2  -0      rpm/rpmio/rpmlua.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: lua/Makefile.am
  ============================================================================
  $ cvs diff -u -r1.15 -r1.16 Makefile.am
  --- lua/Makefile.am	21 Jul 2007 20:07:07 -0000	1.15
  +++ lua/Makefile.am	10 Jan 2008 20:49:36 -0000	1.16
  @@ -30,6 +30,8 @@
   		local/lposix.c \
   		local/lrexlib.h \
   		local/lrexlib.c \
  +		local/luuid.h \
  +		local/luuid.c \
   		linit.c \
   		lauxlib.h \
   		lauxlib.c \
  @@ .
  patch -p0 <<'@@ .'
  Index: lua/local/luuid.c
  ============================================================================
  $ cvs diff -u -r0 -r1.1 luuid.c
  --- /dev/null	2008-01-10 21:46:09 +0100
  +++ luuid.c	2008-01-10 21:49:36 +0100
  @@ -0,0 +1,156 @@
  +/*
  + * luuid.c -- minimum OSSP uuid based UUID extension for RPM Lua
  + * Copyright (C) 2008 Ralf S. Engelschall <rse@engelschall.com>
  + * Licensed under LGPL.
  + */
  +
  +/* NOTICE: This is NOT a general Lua binding for OSSP uuid!
  +   Instead it provides just the minimum functionality to generate a
  +   UUID (output in string representation) and to retrieve a textual
  +   description of a UUID (input in string representation). */
  +
  +#include "config.h"
  +
  +#include <stdio.h>
  +#include <stdlib.h>
  +#include <string.h>
  +
  +#include "lua.h"
  +#include "lauxlib.h"
  +#include "luuid.h"
  +
  +#ifdef LUA_USE_UUID
  +
  +#include "uuid.h"
  +
  +/*  Lua method: <uuid> = uuid.generate(<version>[, <uuid-namespace>, <data>])  */
  +static int luuid_generate(lua_State *L)
  +{
  +    uuid_t *uuid;
  +    uuid_t *uuid_ns = NULL;
  +    const char *uuid_ns_str;
  +    const char *data;
  +    uuid_rc_t rc;
  +    int version;
  +    char result_buf[UUID_LEN_STR+1];
  +    char *result_ptr;
  +    size_t result_len;
  +
  +    /*  fetch arguments  */
  +    if (lua_isnumber(L, 1))
  +        version = lua_tointeger(L, 1);
  +    else
  +        return luaL_argerror(L, 1, "UUID version number");
  +    if (!(version == 1 || (version >= 3 && version <= 5)))
  +        return luaL_argerror(L, 1, "UUID version number");
  +    if (version == 3 || version == 5) {
  +        if (lua_isstring(L, 2))
  +            uuid_ns_str = lua_tostring(L, 2);
  +        else
  +            return luaL_argerror(L, 2, "namespace UUID");
  +        if (lua_isstring(L, 3))
  +            data = lua_tostring(L, 3);
  +        else
  +            return luaL_argerror(L, 3, "plaintext data");
  +        if ((rc = uuid_create(&uuid_ns)) != UUID_RC_OK)
  +            return luaL_error(L, "failed to create UUID NS object: %s", uuid_error(rc));
  +        if ((rc = uuid_load(uuid_ns, uuid_ns_str)) != UUID_RC_OK)
  +            if ((rc = uuid_import(uuid_ns, UUID_FMT_STR, uuid_ns_str, strlen(uuid_ns_str))) != UUID_RC_OK)
  +                return luaL_error(L, "failed to import UUID NS object: %s", uuid_error(rc));
  +    }
  +
  +    /*  create UUID object  */
  +    if ((rc = uuid_create(&uuid)) != UUID_RC_OK)
  +        return luaL_error(L, "failed to create UUID object: %s", uuid_error(rc));
  +
  +    /*  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);
  +        return luaL_error(L, "failed to make UUID object: %s", uuid_error(rc));
  +    }
  +
  +    /*  export UUID in string representation  */
  +    result_ptr = result_buf;
  +    result_len = sizeof(result_buf);
  +    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);
  +        return luaL_error(L, "failed to export UUID object: %s", uuid_error(rc));
  +    }
  +
  +    /*  destroy UUID object(s)  */
  +    uuid_destroy(uuid);
  +    if (uuid_ns != NULL)
  +        uuid_destroy(uuid_ns);
  +
  +    /*  provide result  */
  +    lua_pushstring(L, result_buf);
  +    return 1;
  +}
  +
  +/*  Lua method: <description> = uuid.describe(<uuid>)  */
  +static int luuid_describe(lua_State *L)
  +{
  +    uuid_t *uuid;
  +    const char *uuid_str;
  +    uuid_rc_t rc;
  +    char *result_ptr;
  +
  +    /*  fetch arguments  */
  +    if (lua_isstring(L, 1))
  +        uuid_str = lua_tostring(L, 1);
  +    else
  +        return luaL_argerror(L, 1, "UUID string representation");
  +
  +    /*  create UUID object  */
  +    if ((rc = uuid_create(&uuid)) != UUID_RC_OK)
  +        return luaL_error(L, "failed to create UUID object: %s", uuid_error(rc));
  +
  +    /*  import UUID  */
  +    if ((rc = uuid_import(uuid, UUID_FMT_STR, uuid_str, strlen(uuid_str))) != UUID_RC_OK)
  +        return luaL_error(L, "failed to import UUID object: %s", uuid_error(rc));
  +
  +    /*  export UUID in text description  */
  +    result_ptr = NULL;
  +    if ((rc = uuid_export(uuid, UUID_FMT_TXT, &result_ptr, NULL)) != UUID_RC_OK) {
  +        uuid_destroy(uuid);
  +        return luaL_error(L, "failed to export UUID object: %s", uuid_error(rc));
  +    }
  +
  +    /*  destroy UUID object(s)  */
  +    uuid_destroy(uuid);
  +
  +    /*  provide result  */
  +    lua_pushstring(L, result_ptr);
  +    return 1;
  +}
  +
  +/*  Lua uuid.* method dispatch table  */
  +static const luaL_reg uuid_meta[] = {
  +    { "generate",  luuid_generate },
  +    { "describe",  luuid_describe },
  +    { NULL,        NULL }
  +};
  +
  +#endif
  +
  +/*  Lua extension initialization  */
  +LUALIB_API int luaopen_uuid(lua_State *L)
  +{
  +#ifdef LUA_USE_UUID
  +    luaL_openlib(L, "uuid", uuid_meta, 0);
  +#endif
  +    return 1;
  +}
  +
  @@ .
  patch -p0 <<'@@ .'
  Index: lua/local/luuid.h
  ============================================================================
  $ cvs diff -u -r0 -r1.1 luuid.h
  --- /dev/null	2008-01-10 21:46:09 +0100
  +++ luuid.h	2008-01-10 21:49:36 +0100
  @@ -0,0 +1,7 @@
  +#ifndef LUUID_H
  +#define LUUID_H
  +
  +int luaopen_uuid(lua_State *L)
  +	/*@modifies L @*/;
  +
  +#endif
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
  ============================================================================
  $ cvs diff -u -r1.2057 -r1.2058 CHANGES
  --- rpm/CHANGES	9 Jan 2008 00:36:01 -0000	1.2057
  +++ rpm/CHANGES	10 Jan 2008 20:49:35 -0000	1.2058
  @@ -1,4 +1,5 @@
   5.0.0 -> 5.1a1:
  +    - rse: add OSSP uuid support to RPM Lua via functions uuid.generate() and uuid.describe()
       - rpm.org: Assorted int -> size_t corrections for string lengths.
       - rpm.org: More assorted int -> size_t uses.
   
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/INSTALL
  ============================================================================
  $ cvs diff -u -r2.71 -r2.72 INSTALL
  --- rpm/INSTALL	31 Dec 2007 14:49:27 -0000	2.71
  +++ rpm/INSTALL	10 Jan 2008 20:49:35 -0000	2.72
  @@ -43,6 +43,7 @@
   GNU gettext     optional  0.16    0.17    http://www.gnu.org/software/gettext/
   GNU iconv       optional  1.11    1.11    http://www.gnu.org/software/libiconv/
   PCRE            optional  7.0     7.4     http://www.pcre.org/
  +UUID            optional  1.6.0   1.6.0   http://www.ossp.org/pkg/lib/uuid/
   XAR         [6] optional  1.5.2   1.5.2   http://code.google.com/p/xar/
   DMalloc         optional  5       5.5.2   http://dmalloc.com/
   Electric Fence  optional  2.1     2.1.13  http://perens.com/FreeSoftware/ElectricFence/
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/configure.ac
  ============================================================================
  $ cvs diff -u -r2.270 -r2.271 configure.ac
  --- rpm/configure.ac	5 Jan 2008 10:07:32 -0000	2.270
  +++ rpm/configure.ac	10 Jan 2008 20:49:35 -0000	2.271
  @@ -1070,6 +1070,17 @@
         fi
       ], [])
   
  +dnl # OSSP uuid
  +RPM_CHECK_LIB(
  +    [OSSP uuid], [uuid],
  +    [uuid], [uuid_import], [uuid.h],
  +    [no,external:none], [],
  +    [ dnl # enable OSSP uuid native API support for embedded Lua
  +      if test ".$WITH_LUA" = .yes; then
  +          WITH_LUA_SUBDIR_DEF="$WITH_LUA_SUBDIR_DEF -DLUA_USE_UUID"
  +      fi
  +    ], [])
  +
   dnl # XAR
   RPM_CHECK_LIB(
       [XAR], [xar],
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/devtool.conf
  ============================================================================
  $ cvs diff -u -r2.171 -r2.172 devtool.conf
  --- rpm/devtool.conf	6 Jan 2008 19:22:46 -0000	2.171
  +++ rpm/devtool.conf	10 Jan 2008 20:49:35 -0000	2.172
  @@ -227,6 +227,7 @@
           v_libxml2="2.6.30"
           v_xar="1.5.2"
           v_pcre="7.4"
  +        v_uuid="1.6.0"
           v_config="20080105"
   
           #   third-party distribution files
  @@ -250,6 +251,7 @@
           dist="${dist} libxml2-${v_libxml2}.tar.gz,http://rpm5.org/files/3rd/,ftp://xmlsoft.org/libxml2/"
           dist="${dist} xar-${v_xar}.tar.gz,http://rpm5.org/files/3rd/,http://xar.googlecode.com/files/"
           dist="${dist} pcre-${v_pcre}.tar.gz,http://rpm5.org/files/3rd/,ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/"
  +        dist="${dist} uuid-${v_uuid}.tar.gz,http://rpm5.org/files/3rd/,ftp://ftp.ossp.org/pkg/lib/uuid/"
   
           #   third-party distribution patches (for portability and bugfix reasons only)
           dist="${dist} automake-${v_automake}.patch,http://rpm5.org/files/3rd/"
  @@ -836,6 +838,25 @@
                   ) || exit $?
               ) || exit $?
           fi
  +
  +        #   OSSP uuid (uninstalled third-party library)
  +        if [ ! -d "$base3rd/bin/$platform/uuid-${v_uuid}" ]; then
  +            echo "++ building third-party library uuid-${v_uuid}"
  +            (   cd $base3rd/bin/$platform
  +                rm -rf uuid-${v_uuid}
  +                $gzip -d -c ../../src/uuid-${v_uuid}.tar.gz | $tar xf -
  +                (   cd uuid-${v_uuid}
  +                    $SHTOOL subst \
  +                        -e '/LINENO: error: C[+]* preprocessor/{N;N;N;N;s/.*/:/;}' \
  +                        configure
  +                    CC="$cc" \
  +                    GREP="grep" \
  +                    ./configure \
  +                        --disable-shared
  +                    make
  +                ) || exit $?
  +            ) || exit $?
  +        fi
       }
   
       #   configure build environment
  @@ -893,6 +914,7 @@
               OPTION="$OPTION --with-lua=\"$base3rd/bin/$platform/lua-${v_lua}/src\""
           fi
           OPTION="$OPTION --with-pcre=\"$base3rd/bin/$platform/pcre-${v_pcre}\""
  +        OPTION="$OPTION --with-uuid=\"$base3rd/bin/$platform/uuid-${v_uuid}\""
           OPTION="$OPTION --with-file=\"$base3rd/bin/$platform/file-${v_file}\""
           OPTION="$OPTION --with-zlib=\"$base3rd/bin/$platform/zlib-${v_zlib}\""
           OPTION="$OPTION --with-bzip2=\"$base3rd/bin/$platform/bzip2-${v_bzip2}\""
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmlua.c
  ============================================================================
  $ cvs diff -u -r2.37 -r2.38 rpmlua.c
  --- rpm/rpmio/rpmlua.c	1 Jan 2008 20:27:52 -0000	2.37
  +++ rpm/rpmio/rpmlua.c	10 Jan 2008 20:49:36 -0000	2.38
  @@ -17,6 +17,7 @@
   #include <llocal.h>
   #include <lposix.h>
   #include <lrexlib.h>
  +#include <luuid.h>
   #endif
   
   #include <unistd.h>
  @@ -78,6 +79,7 @@
   #ifdef WITH_LUA_INTERNAL
   	{"posix", luaopen_posix},
   	{"rex", luaopen_rex},
  +	{"uuid", luaopen_uuid},
   	{"local", luaopen_local},
   #endif
   	{"rpm", luaopen_rpm},
  @@ .
Received on Thu Jan 10 21:49:36 2008
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.