Index: ossp-pkg/uuid/ChangeLog RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/ChangeLog,v rcsdiff -q -kk '-r1.115' '-r1.116' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/ChangeLog,v' 2>/dev/null --- ChangeLog 2006/05/10 09:16:26 1.115 +++ ChangeLog 2006/05/11 09:37:27 1.116 @@ -11,7 +11,11 @@ This is a list of all changes to OSSP uuid. For a more brief summary please have a look at the NEWS file. - Changes between 1.4.2 and 1.4.3 (13-Mar-2006 to XX-May-2006) + Changes between 1.4.2 and 1.5.0 (13-Mar-2006 to XX-May-2006) + + o Add full support for Single Integer Value (SIV) UUID representation + for both importing and exporting in C/C++/Perl/PHP APIs. + [Ralf S. Engelschall] o Upgrade build environment to GNU shtool 2.0.6 [Ralf S. Engelschall] Index: ossp-pkg/uuid/Makefile.in RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/Makefile.in,v co -q -kk -p'1.41' '/v/ossp/cvs/ossp-pkg/uuid/Attic/Makefile.in,v' | diff -u /dev/null - -L'ossp-pkg/uuid/Makefile.in' 2>/dev/null --- ossp-pkg/uuid/Makefile.in +++ - 2024-05-09 10:46:24.983492583 +0200 @@ -0,0 +1,356 @@ +## +## OSSP uuid - Universally Unique Identifier +## Copyright (c) 2004-2006 Ralf S. Engelschall +## Copyright (c) 2004-2006 The OSSP Project +## +## This file is part of OSSP uuid, a library for the generation +## of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/ +## +## Permission to use, copy, modify, and distribute this software for +## any purpose with or without fee is hereby granted, provided that +## the above copyright notice and this permission notice appear in all +## copies. +## +## 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 THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR +## 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. +## +## Makefile.in: make(1) build procedure +## + +@SET_MAKE@ + +VPATH = @srcdir@ +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +S = $(srcdir) +C = . + +DESTDIR = +prefix = @prefix@ +exec_prefix = @exec_prefix@ +bindir = @bindir@ +libdir = @libdir@ +includedir = @includedir@ +mandir = @mandir@ + +CC = @CC@ +CXX = @CXX@ +CPPFLAGS = -I. -I$(S) @CPPFLAGS@ @DEFS@ +CFLAGS = @CFLAGS@ +CXXFLAGS = @CXXFLAGS@ +LDFLAGS = @LDFLAGS@ +LIBS = @LIBS@ +RM = rm -f +CP = cp +RMDIR = rmdir +SHTOOL = $(S)/shtool +LIBTOOL = $(C)/libtool +TRUE = true +POD2MAN = pod2man +PERL = @PERL@ +PHP = @PHP@ +PG_CONFIG = @PG_CONFIG@ + +LIB_NAME = libuuid.la +LIB_OBJS = uuid.lo uuid_md5.lo uuid_sha1.lo uuid_prng.lo uuid_mac.lo uuid_ui64.lo uuid_ui128.lo uuid_str.lo + +DCE_NAME = libuuid_dce.la +DCE_OBJS = uuid_dce.lo $(LIB_OBJS) + +CXX_NAME = libuuid++.la +CXX_OBJS = uuid++.lo $(LIB_OBJS) + +PRG_NAME = uuid +PRG_OBJS = uuid_cli.o + +MAN_NAME = uuid.3 uuid++.3 uuid.1 + +PERL_NAME = $(S)/perl/blib/lib/OSSP/uuid.pm +PERL_OBJS = $(S)/perl/uuid.pm + +PHP_NAME = $(S)/php/modules/uuid.so +PHP_OBJS = $(S)/php/uuid.c + +PGSQL_NAME = $(S)/pgsql/libuuid.so +PGSQL_OBJS = $(S)/pgsql/uuid.c + +TARGETS = $(LIB_NAME) @DCE_NAME@ @CXX_NAME@ $(PRG_NAME) @PERL_NAME@ @PHP_NAME@ @PGSQL_NAME@ + +WITH_DCE = @WITH_DCE@ +WITH_CXX = @WITH_CXX@ +WITH_PERL = @WITH_PERL@ +WITH_PERL_COMPAT = @WITH_PERL_COMPAT@ +WITH_PHP = @WITH_PHP@ +WITH_PGSQL = @WITH_PGSQL@ + +.SUFFIXES: +.SUFFIXES: .c .cc .o .lo + +all: $(TARGETS) + +.c.o: + $(CC) $(CPPFLAGS) $(CFLAGS) -c $< + +.cc.o: + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< + +.c.lo: + @$(LIBTOOL) --mode=compile $(CC) $(CPPFLAGS) $(CFLAGS) -c $< + +.cc.lo: + @$(LIBTOOL) --mode=compile $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< + +$(LIB_NAME): $(LIB_OBJS) + @$(LIBTOOL) --mode=link $(CC) -o $(LIB_NAME) $(LIB_OBJS) -rpath $(libdir) \ + -version-info `$(SHTOOL) version -l c -d libtool $(S)/uuid_vers.h` + +$(DCE_NAME): $(DCE_OBJS) + @$(LIBTOOL) --mode=link $(CC) -o $(DCE_NAME) $(DCE_OBJS) -rpath $(libdir) \ + -version-info `$(SHTOOL) version -l c -d libtool $(S)/uuid_vers.h` + +$(CXX_NAME): $(CXX_OBJS) + @$(LIBTOOL) --mode=link $(CXX) -o $(CXX_NAME) $(CXX_OBJS) -rpath $(libdir) \ + -version-info `$(SHTOOL) version -l c -d libtool $(S)/uuid_vers.h` + +$(PRG_NAME): $(PRG_OBJS) $(LIB_NAME) + @$(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o $(PRG_NAME) $(PRG_OBJS) $(LIB_NAME) $(LIBS) + +$(PERL_NAME): $(PERL_OBJS) $(LIB_NAME) + @cd $(S)/perl && $(PERL) Makefile.PL PREFIX=$(prefix) COMPAT=$(WITH_PERL_COMPAT) && $(MAKE) $(MFLAGS) all + @touch $(PERL_NAME) + +$(PHP_NAME): $(PHP_OBJS) $(LIB_NAME) + @cd $(S)/php && $(MAKE) $(MFLAGS) -f Makefile.local PHP=$(PHP) + @touch $(PHP_NAME) + +$(PGSQL_NAME): $(PGSQL_OBJS) $(LIB_NAME) + @cd $(S)/pgsql && $(MAKE) $(MFLAGS) PG_CONFIG=$(PG_CONFIG) + @touch $(PGSQL_NAME) + +uuid.lo: $(S)/uuid.c uuid.h $(S)/uuid_md5.h $(S)/uuid_sha1.h $(S)/uuid_prng.h $(S)/uuid_mac.h $(S)/uuid_ui64.h $(S)/uuid_ui128.h $(S)/uuid_str.h $(S)/uuid_bm.h $(S)/uuid_ac.h +uuid_mac.lo: $(S)/uuid_mac.c $(S)/uuid_mac.h +uuid_md5.lo: $(S)/uuid_md5.c $(S)/uuid_md5.h +uuid_sha1.lo: $(S)/uuid_sha1.c $(S)/uuid_sha1.h +uuid_prng.lo: $(S)/uuid_prng.c $(S)/uuid_prng.h +uuid_str.lo: $(S)/uuid_str.c $(S)/uuid_str.h +uuid_ui64.lo: $(S)/uuid_ui64.c $(S)/uuid_ui64.h +uuid_ui128.lo: $(S)/uuid_ui64.c $(S)/uuid_ui128.h +uuid_dce.lo: $(S)/uuid_dce.c uuid.h $(S)/uuid_dce.h +uuid_cli.o: $(S)/uuid_cli.c uuid.h +uuid++.lo: $(S)/uuid++.cc $(S)/uuid++.hh + +man: uuid.3 uuid++.3 uuid-config.1 uuid.1 +uuid.3: uuid.pod + V1=`$(SHTOOL) version -l c -d short $(S)/uuid_vers.h`; \ + V2=`$(SHTOOL) version -l c -d long $(S)/uuid_vers.h`; \ + D=`$(SHTOOL) version -l c -d long $(S)/uuid_vers.h | sed -e 's;.*(;;' -e 's;).*;;'`; \ + $(POD2MAN) --quotes=none \ + --section=3 --center="Universally Unique Identifier" \ + --release="$$D" --date="OSSP uuid $$V1" $(S)/uuid.pod | \ + sed -e "s;UUID_VERSION_STR;$$V2;" >uuid.3 +uuid++.3: uuid++.pod + V1=`$(SHTOOL) version -l c -d short $(S)/uuid_vers.h`; \ + V2=`$(SHTOOL) version -l c -d long $(S)/uuid_vers.h`; \ + D=`$(SHTOOL) version -l c -d long $(S)/uuid_vers.h | sed -e 's;.*(;;' -e 's;).*;;'`; \ + $(POD2MAN) --quotes=none \ + --section=3 --center="Universally Unique Identifier" \ + --release="$$D" --date="OSSP uuid $$V1" $(S)/uuid++.pod | \ + sed -e "s;UUID_VERSION_STR;$$V2;" >uuid++.3 +uuid-config.1: uuid-config.pod + V1=`$(SHTOOL) version -l c -d short $(S)/uuid_vers.h`; \ + V2=`$(SHTOOL) version -l c -d long $(S)/uuid_vers.h`; \ + D=`$(SHTOOL) version -l c -d long $(S)/uuid_vers.h | sed -e 's;.*(;;' -e 's;).*;;'`; \ + $(POD2MAN) --quotes=none \ + --section=1 --center="Universally Unique Identifier" \ + --release="$$D" --date="OSSP uuid $$V1" $(S)/uuid-config.pod | \ + sed -e "s;UUID_VERSION_STR;$$V2;" >uuid-config.1 +uuid.1: uuid_cli.pod + V1=`$(SHTOOL) version -l c -d short $(S)/uuid_vers.h`; \ + V2=`$(SHTOOL) version -l c -d long $(S)/uuid_vers.h`; \ + D=`$(SHTOOL) version -l c -d long $(S)/uuid_vers.h | sed -e 's;.*(;;' -e 's;).*;;'`; \ + $(CP) $(S)/uuid_cli.pod /tmp/uuid.pod; \ + $(POD2MAN) --quotes=none \ + --section=1 --center="Universally Unique Identifier" \ + --release="$$D" --date="OSSP uuid $$V1" /tmp/uuid.pod | \ + sed -e "s;UUID_VERSION_STR;$$V2;" >uuid.1; \ + $(RM) /tmp/uuid.pod + +check: all + @echo "==== UUID version 1 (time and node based): 4 single iterations"; \ + $(LIBTOOL) --mode=execute ./$(PRG_NAME) -v1 -n 4 -1 + @echo "==== UUID version 1 (time and node based): 4 subsequent iterations"; \ + $(LIBTOOL) --mode=execute ./$(PRG_NAME) -v1 -n 4 + @echo "==== UUID version 3 (name based, MD5): 2 times repeated"; \ + $(LIBTOOL) --mode=execute ./$(PRG_NAME) -v3 -n 2 ns:URL http://www.ossp.org/ + @echo "==== UUID version 5 (name based, SHA-1): 2 times repeated"; \ + $(LIBTOOL) --mode=execute ./$(PRG_NAME) -v5 -n 2 ns:URL http://www.ossp.org/ + @echo "==== UUID version 4 (random data based): 4 single iterations"; \ + $(LIBTOOL) --mode=execute ./$(PRG_NAME) -v4 -n 4 -1 + @echo "==== UUID version 4 (random data based): 4 subsequent iterations"; \ + $(LIBTOOL) --mode=execute ./$(PRG_NAME) -v4 -n 4 + @echo "==== UUID version 1 generation and decoding"; \ + $(LIBTOOL) --mode=execute ./$(PRG_NAME) -d `$(LIBTOOL) --mode=execute ./$(PRG_NAME) -v1`; \ + $(LIBTOOL) --mode=execute ./$(PRG_NAME) -d `$(LIBTOOL) --mode=execute ./$(PRG_NAME) -v1 -m` + @echo "==== UUID version 3 generation and decoding"; \ + $(LIBTOOL) --mode=execute ./$(PRG_NAME) -d `$(LIBTOOL) --mode=execute ./$(PRG_NAME) -v3 ns:URL http://www.ossp.org/` + @echo "==== UUID version 5 generation and decoding"; \ + $(LIBTOOL) --mode=execute ./$(PRG_NAME) -d `$(LIBTOOL) --mode=execute ./$(PRG_NAME) -v5 ns:URL http://www.ossp.org/` + @echo "==== UUID version 3 generation and decoding"; \ + $(LIBTOOL) --mode=execute ./$(PRG_NAME) -d `$(LIBTOOL) --mode=execute ./$(PRG_NAME) -v4` + -@if [ ".$(WITH_PERL)" = .yes ]; then \ + echo "==== Perl bindings to C API"; \ + (cd $(S)/perl && $(MAKE) $(MFLAGS) test); \ + fi + -@if [ ".$(WITH_PHP)" = .yes ]; then \ + echo "==== PHP bindings to C API"; \ + (cd $(S)/php && $(MAKE) $(MFLAGS) -f Makefile.local test PHP=$(PHP)); \ + fi + -@if [ ".$(WITH_PGSQL)" = .yes ]; then \ + echo "==== PGSQL bindings to C API"; \ + (cd $(S)/pgsql && $(MAKE) $(MFLAGS) test PG_CONFIG=$(PG_CONFIG)); \ + fi + +.PHONY: install +install: + $(SHTOOL) mkdir -f -p -m 755 $(DESTDIR)$(prefix) + $(SHTOOL) mkdir -f -p -m 755 $(DESTDIR)$(bindir) + $(SHTOOL) mkdir -f -p -m 755 $(DESTDIR)$(includedir) + $(SHTOOL) mkdir -f -p -m 755 $(DESTDIR)$(libdir)/pkgconfig + $(SHTOOL) mkdir -f -p -m 755 $(DESTDIR)$(mandir)/man3 + $(SHTOOL) mkdir -f -p -m 755 $(DESTDIR)$(mandir)/man1 + $(SHTOOL) install -c -m 755 uuid-config $(DESTDIR)$(bindir)/ + $(SHTOOL) install -c -m 644 $(S)/uuid-config.1 $(DESTDIR)$(mandir)/man1/ + $(SHTOOL) install -c -m 644 $(S)/uuid.pc $(DESTDIR)$(libdir)/pkgconfig/ + $(SHTOOL) install -c -m 644 uuid.h $(DESTDIR)$(includedir)/ + -@if [ ".$(WITH_DCE)" = .yes ]; then \ + echo "$(SHTOOL) install -c -m 644 $(S)/uuid_dce.h $(DESTDIR)$(includedir)/"; \ + $(SHTOOL) install -c -m 644 $(S)/uuid_dce.h $(DESTDIR)$(includedir)/; \ + fi + -@if [ ".$(WITH_CXX)" = .yes ]; then \ + echo "$(SHTOOL) install -c -m 644 $(S)/uuid++.hh $(DESTDIR)$(includedir)/"; \ + $(SHTOOL) install -c -m 644 $(S)/uuid++.hh $(DESTDIR)$(includedir)/; \ + fi + $(SHTOOL) install -c -m 644 $(S)/uuid.3 $(DESTDIR)$(mandir)/man3/ + -@if [ ".$(WITH_CXX)" = .yes ]; then \ + echo "$(SHTOOL) install -c -m 644 $(S)/uuid++.3 $(DESTDIR)$(mandir)/man3/"; \ + $(SHTOOL) install -c -m 644 $(S)/uuid++.3 $(DESTDIR)$(mandir)/man3/; \ + fi + @$(LIBTOOL) --mode=install $(SHTOOL) install -c -m 644 libuuid.la $(DESTDIR)$(libdir)/ + -@if [ ".$(WITH_DCE)" = .yes ]; then \ + $(LIBTOOL) --mode=install $(SHTOOL) install -c -m 644 libuuid_dce.la $(DESTDIR)$(libdir)/; \ + fi + -@if [ ".$(WITH_CXX)" = .yes ]; then \ + $(LIBTOOL) --mode=install $(SHTOOL) install -c -m 644 libuuid++.la $(DESTDIR)$(libdir)/; \ + fi + @$(LIBTOOL) --mode=install $(SHTOOL) install -c -s -m 755 uuid $(DESTDIR)$(bindir)/ + $(SHTOOL) install -c -m 644 $(S)/uuid.1 $(DESTDIR)$(mandir)/man1/ + -@if [ ".$(WITH_PERL)" = .yes ]; then \ + (cd $(S)/perl && $(MAKE) $(MFLAGS) install DESTDIR=$(DESTDIR)); \ + fi + -@if [ ".$(WITH_PHP)" = .yes ]; then \ + (cd $(S)/php && $(MAKE) $(MFLAGS) -f Makefile.local install EXTDIR=$(prefix)/lib/php PHP=$(PHP) DESTDIR=$(DESTDIR)); \ + fi + -@if [ ".$(WITH_PGSQL)" = .yes ]; then \ + (cd $(S)/pgsql && $(MAKE) $(MFLAGS) install DESTDIR=$(DESTDIR) PG_CONFIG=$(PG_CONFIG)); \ + fi + +.PHONY: uninstall +uninstall: + -$(RM) $(DESTDIR)$(mandir)/man1/uuid.1 + -@$(LIBTOOL) --mode=uninstall $(RM) $(DESTDIR)$(bindir)/uuid + -@$(LIBTOOL) --mode=uninstall $(RM) $(DESTDIR)$(libdir)/libuuid.la + -@if [ ".$(WITH_DCE)" = .yes ]; then \ + $(LIBTOOL) --mode=uninstall $(RM) $(DESTDIR)$(libdir)/libuuid_dce.la; \ + fi + -@if [ ".$(WITH_CXX)" = .yes ]; then \ + $(LIBTOOL) --mode=uninstall $(RM) $(DESTDIR)$(libdir)/libuuid++.la; \ + fi + -$(RM) $(DESTDIR)$(mandir)/man3/uuid.3 + -@if [ ".$(WITH_CXX)" = .yes ]; then \ + echo "$(RM) $(DESTDIR)$(mandir)/man3/uuid++.3"; \ + $(RM) $(DESTDIR)$(mandir)/man3/uuid++.3; \ + fi + -$(RM) $(DESTDIR)$(includedir)/uuid.h + -@if [ ".$(WITH_DCE)" = .yes ]; then \ + echo "$(RM) $(DESTDIR)$(includedir)/uuid_dce.h"; \ + $(RM) $(DESTDIR)$(includedir)/uuid_dce.h; \ + fi + -@if [ ".$(WITH_CXX)" = .yes ]; then \ + echo "$(RM) $(DESTDIR)$(includedir)/uuid++.hh"; \ + $(RM) $(DESTDIR)$(includedir)/uuid++.hh; \ + fi + -$(RM) $(DESTDIR)$(libdir)/pkgconfig/uuid.pc + -$(RM) $(DESTDIR)$(mandir)/man1/uuid-config.1 + -$(RM) $(DESTDIR)$(bindir)/uuid-config + -$(RMDIR) $(DESTDIR)$(mandir)/man1 >/dev/null 2>&1 || $(TRUE) + -$(RMDIR) $(DESTDIR)$(mandir)/man3 >/dev/null 2>&1 || $(TRUE) + -$(RMDIR) $(DESTDIR)$(mandir) >/dev/null 2>&1 || $(TRUE) + -$(RMDIR) $(DESTDIR)$(libdir)/pkgconfig >/dev/null 2>&1 || $(TRUE) + -$(RMDIR) $(DESTDIR)$(libdir) >/dev/null 2>&1 || $(TRUE) + -$(RMDIR) $(DESTDIR)$(includedir) >/dev/null 2>&1 || $(TRUE) + -$(RMDIR) $(DESTDIR)$(bindir) >/dev/null 2>&1 || $(TRUE) + -$(RMDIR) $(DESTDIR)$(prefix) >/dev/null 2>&1 || $(TRUE) + +.PHONY: clean +clean: + -$(RM) $(LIB_NAME) $(LIB_OBJS) + -@if [ ".$(WITH_DCE)" = .yes ]; then \ + echo "$(RM) $(DCE_NAME) $(DCE_OBJS)"; \ + $(RM) $(DCE_NAME) $(DCE_OBJS); \ + fi + -@if [ ".$(WITH_CXX)" = .yes ]; then \ + echo "$(RM) $(CXX_NAME) $(CXX_OBJS)"; \ + $(RM) $(CXX_NAME) $(CXX_OBJS); \ + fi + -$(RM) $(PRG_NAME) $(PRG_OBJS) + -$(RM) -r .libs >/dev/null 2>&1 || $(TRUE) + -$(RM) *.o *.lo + -@if [ ".$(WITH_PERL)" = .yes ]; then \ + (cd $(S)/perl && $(MAKE) $(MFLAGS) clean || true); \ + fi + -@if [ ".$(WITH_PHP)" = .yes ]; then \ + (cd $(S)/php && $(MAKE) $(MFLAGS) -f Makefile.local clean || true); \ + fi + -@if [ ".$(WITH_PGSQL)" = .yes ]; then \ + (cd $(S)/pgsql && $(MAKE) $(MFLAGS) clean PG_CONFIG=$(PG_CONFIG) || true); \ + fi + +distclean: clean + -$(RM) config.log config.status config.cache + -$(RM) Makefile config.h uuid-config uuid.h uuid.pc + -$(RM) libtool + -@if [ ".$(WITH_PERL)" = .yes ]; then \ + (cd $(S)/perl && $(MAKE) $(MFLAGS) distclean || true; rm -f Makefile.old); \ + fi + -@if [ ".$(WITH_PHP)" = .yes ]; then \ + (cd $(S)/php && $(MAKE) $(MFLAGS) -f Makefile.local distclean || true); \ + fi + -@if [ ".$(WITH_PGSQL)" = .yes ]; then \ + (cd $(S)/pgsql && $(MAKE) $(MFLAGS) distclean PG_CONFIG=$(PG_CONFIG) || true); \ + fi + +realclean: distclean + -$(RM) uuid.3 uuid.1 + -$(RM) configure config.h.in + -$(RM) shtool + -$(RM) ltmain.sh libtool.m4 config.guess config.sub + -@if [ ".$(WITH_PERL)" = .yes ]; then \ + (cd $(S)/perl && $(MAKE) $(MFLAGS) realclean || true; rm -f Makefile.old); \ + fi + -@if [ ".$(WITH_PHP)" = .yes ]; then \ + (cd $(S)/php && $(MAKE) $(MFLAGS) -f Makefile.local realclean || true); \ + fi + -@if [ ".$(WITH_PGSQL)" = .yes ]; then \ + (cd $(S)/pgsql && $(MAKE) $(MFLAGS) realclean PG_CONFIG=$(PG_CONFIG) || true); \ + fi + Index: ossp-pkg/uuid/perl/uuid.pm RCS File: /v/ossp/cvs/ossp-pkg/uuid/perl/Attic/uuid.pm,v rcsdiff -q -kk '-r1.17' '-r1.18' -u '/v/ossp/cvs/ossp-pkg/uuid/perl/Attic/uuid.pm,v' 2>/dev/null --- uuid.pm 2006/03/13 09:42:48 1.17 +++ uuid.pm 2006/05/11 09:37:30 1.18 @@ -129,6 +129,7 @@ UUID_VERSION UUID_LEN_BIN UUID_LEN_STR + UUID_LEN_SIV UUID_RC_OK UUID_RC_ARG UUID_RC_MEM @@ -142,6 +143,7 @@ UUID_MAKE_MC UUID_FMT_BIN UUID_FMT_STR + UUID_FMT_SIV UUID_FMT_TXT )], 'func' => [qw( @@ -256,6 +258,7 @@ my ($self, $fmt, $data_ptr, $data_len) = @_; if ($fmt eq 'bin') { $fmt = $self->UUID_FMT_BIN; } elsif ($fmt eq 'str') { $fmt = $self->UUID_FMT_STR; } + elsif ($fmt eq 'siv') { $fmt = $self->UUID_FMT_SIV; } elsif ($fmt eq 'txt') { $fmt = $self->UUID_FMT_TXT; } else { croak("invalid format \"$fmt\""); } $data_len ||= length($data_ptr); # functional redudant, but Perl dislikes undef value here @@ -283,6 +286,7 @@ my $data_ptr; if ($fmt eq 'bin') { $fmt = $self->UUID_FMT_BIN; } elsif ($fmt eq 'str') { $fmt = $self->UUID_FMT_STR; } + elsif ($fmt eq 'siv') { $fmt = $self->UUID_FMT_SIV; } elsif ($fmt eq 'txt') { $fmt = $self->UUID_FMT_TXT; } else { croak("invalid format \"$fmt\""); } $self->{-rc} = uuid_export($self->{-uuid}, $fmt, $data_ptr, undef); Index: ossp-pkg/uuid/perl/uuid.pod RCS File: /v/ossp/cvs/ossp-pkg/uuid/perl/Attic/uuid.pod,v co -q -kk -p'1.11' '/v/ossp/cvs/ossp-pkg/uuid/perl/Attic/uuid.pod,v' | diff -u /dev/null - -L'ossp-pkg/uuid/perl/uuid.pod' 2>/dev/null --- ossp-pkg/uuid/perl/uuid.pod +++ - 2024-05-09 10:46:24.990667464 +0200 @@ -0,0 +1,207 @@ +## +## OSSP uuid - Universally Unique Identifier +## Copyright (c) 2004-2006 Ralf S. Engelschall +## Copyright (c) 2004-2006 The OSSP Project +## +## This file is part of OSSP uuid, a library for the generation +## of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/ +## +## Permission to use, copy, modify, and distribute this software for +## any purpose with or without fee is hereby granted, provided that +## the above copyright notice and this permission notice appear in all +## copies. +## +## 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 THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR +## 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. +## +## uuid.pod: Perl Binding (Perl/POD part) +## + +=pod + +=head1 NAME + +OSSP::uuid - B Perl Binding + +=head1 DESCRIPTION + +B is a ISO-C:1999 application programming interface (API) +and corresponding command line interface (CLI) for the generation of +DCE 1.1, ISO/IEC 11578:1996 and RFC 4122 compliant I (UUID). It supports DCE 1.1 variant UUIDs of version 1 (time +and node based), version 3 (name based, MD5), version 4 (random number +based) and version 5 (name based, SHA-1). Additional API bindings are +provided for the languages ISO-C++:1998, Perl:5 and PHP:4/5. Optional +backward compatibility exists for the ISO-C DCE-1.1 and Perl Data::UUID +APIs. + +B is the Perl binding to the B API. +Three variants are provided: + +=head2 TIE-STYLE API + +The TIE-style API is a functionality-reduced wrapper around the OO-style +API and intended for very high-level convenience programming: + +=over 4 + +=item C + +=item BC< my $uuid, 'OSSP::uuid::tie', $mode, ...;> + +=item C<$uuid = [ $mode, ... ];> + +=item C + +=item C + +=back + +=head2 OO-STYLE API + +The OO-style API is a wrapper around the C-style API and intended for +high-level regular programming. + +=over 4 + +=item C + +=item CBC< OSSP::uuid;> + +=item C<$uuid-E>BC<($name);> + +=item C<$uuid-E>BC<($mode, ...);> + +=item C<$result = $uuid-E>BC<();> + +=item C<$result = $uuid-E>BC<($uuid2);> + +=item C<$uuid-E>BC<($fmt, $data_ptr);> + +=item C<$data_ptr = $uuid-E>BC<($fmt);> + +=item C<[(]$str[, $rc)] = $uuid-E>BC<();> + +=item C<$ver = $uuid-E>BC<();> + +=item C + +=back + +Additionally, the strings C<"v1">, C<"v3">, C<"v4">, C<"v5"> and C<"mc"> +can be used in C<$mode> and the strings C<"bin">, C<"str">, and C<"txt"> +can be used for C<$fmt>. + +=head2 C-STYLE API + +The C-style API is a direct mapping +of the B ISO-C API to Perl and is intended for low-level +programming. See uuid(3) for a description of the functions and +their expected arguments. + +=over 4 + +=item C + +=item CBC<($uuid);> + +=item C<$rc = >BC<($uuid, $name);> + +=item C<$rc = >BC<($uuid, $mode, ...);> + +=item C<$rc = >BC<($uuid, $result);> + +=item C<$rc = >BC<($uuid, $uuid2, $result);> + +=item C<$rc = >BC<($uuid, $fmt, $data_ptr, $data_len);> + +=item C<$rc = >BC<($uuid, $fmt, $data_ptr, $data_len);> + +=item C<$str = >BC<($rc);> + +=item C<$ver = >BC<();> + +=item C<$rc = >BC<($uuid);> + +=back + +Additionally, the following constants are exported for use in C<$rc>, C<$mode>, C<$fmt> and C<$ver>: + +C, +C, +C, +C, +C, +C, +C, +C, +C, +C, +C, +C, +C, +C, +C, +C, +C, +C. + +=head1 EXAMPLES + +The following two examples create the version 3 UUID +C<02d9e6d5-9467-382e-8f9b-9300a64ac3cd>, both via the OO-style and the +C-style API. Error handling is omitted here for easier reading, but has +to be added for production-quality code. + + # TIE-style API (very high-level) + use OSSP::uuid; + tie my $uuid, 'OSSP::uuid::tie'; + $uuid = [ "v1" ]; + print "UUIDs: $uuid, $uuid, $uuid\n"; + $uuid = [ "v3", "ns:URL", "http://www.ossp.org/" ]; + print "UUIDs: $uuid, $uuid, $uuid\n"; + untie $uuid; + + # OO-style API (high-level) + use OSSP::uuid; + my $uuid = new OSSP::uuid; + my $uuid_ns = new OSSP::uuid; + $uuid_ns->load("ns:URL"); + $uuid->make("v3", $uuid_ns, "http://www.ossp.org/"); + undef $uuid_ns; + my $str = $uuid->export("str"); + undef $uuid; + print "$str\n"; + + # C-style API (low-level) + use OSSP::uuid qw(:all); + my $uuid; uuid_create($uuid); + my $uuid_ns; uuid_create($uuid_ns); + uuid_load($uuid_ns, "ns:URL"); + uuid_make($uuid, UUID_MAKE_V3, $uuid_ns, "http://www.ossp.org/"); + uuid_destroy($uuid_ns); + my $str; uuid_export($uuid, UUID_FMT_STR, $str, undef); + uuid_destroy($uuid); + print "$str\n"; + +=head1 SEE ALSO + +uuid(1), uuid-config(1), uuid(3). + +=head1 HISTORY + +The Perl binding B to B was implemented in +November 2004 by Ralf S. Engelschall Erse@engelschall.comE. + +=cut + Index: ossp-pkg/uuid/perl/uuid.ts RCS File: /v/ossp/cvs/ossp-pkg/uuid/perl/Attic/uuid.ts,v rcsdiff -q -kk '-r1.4' '-r1.5' -u '/v/ossp/cvs/ossp-pkg/uuid/perl/Attic/uuid.ts,v' 2>/dev/null --- uuid.ts 2006/01/13 06:44:33 1.4 +++ uuid.ts 2006/05/11 09:37:30 1.5 @@ -27,7 +27,7 @@ ## uuid.ts: Perl Binding (Perl test suite part) ## -use Test::More tests => 35; +use Test::More tests => 36; ## ## Module Loading @@ -87,6 +87,10 @@ ok(( $rc == UUID_RC_OK and $ptr eq "02d9e6d5-9467-382e-8f9b-9300a64ac3cd" and $len == UUID_LEN_STR), "uuid_export (5)"); +$rc = uuid_export($uuid_ns, UUID_FMT_SIV, $ptr, $len); +ok(( $rc == UUID_RC_OK + and $ptr eq "3789866285607910888100818383505376205" + and $len <= UUID_LEN_SIV), "uuid_export (6)"); $rc = uuid_destroy($uuid_ns); ok($rc == UUID_RC_OK, "uuid_destroy (1)"); Index: ossp-pkg/uuid/perl/uuid.xs RCS File: /v/ossp/cvs/ossp-pkg/uuid/perl/Attic/uuid.xs,v rcsdiff -q -kk '-r1.7' '-r1.8' -u '/v/ossp/cvs/ossp-pkg/uuid/perl/Attic/uuid.xs,v' 2>/dev/null --- uuid.xs 2006/03/13 09:14:23 1.7 +++ uuid.xs 2006/05/11 09:37:30 1.8 @@ -48,6 +48,7 @@ { "UUID_VERSION", UUID_VERSION }, { "UUID_LEN_BIN", UUID_LEN_BIN }, { "UUID_LEN_STR", UUID_LEN_STR }, + { "UUID_LEN_SIV", UUID_LEN_SIV }, { "UUID_RC_OK", UUID_RC_OK }, { "UUID_RC_ARG", UUID_RC_ARG }, { "UUID_RC_MEM", UUID_RC_MEM }, @@ -61,6 +62,7 @@ { "UUID_MAKE_MC", UUID_MAKE_MC }, { "UUID_FMT_BIN", UUID_FMT_BIN }, { "UUID_FMT_STR", UUID_FMT_STR }, + { "UUID_FMT_SIV", UUID_FMT_SIV }, { "UUID_FMT_TXT", UUID_FMT_TXT } }; INPUT: @@ -201,7 +203,9 @@ data_len = 0; RETVAL = uuid_export(uuid, fmt, &data_ptr, &data_len); if (RETVAL == UUID_RC_OK) { - if (fmt == UUID_FMT_STR || fmt == UUID_FMT_TXT) + if (fmt == UUID_FMT_SIV) + data_len = strlen((char *)data_ptr); + else if (fmt == UUID_FMT_STR || fmt == UUID_FMT_TXT) data_len--; /* Perl doesn't wish NUL-termination on strings */ sv_setpvn(ST(2), data_ptr, data_len); free(data_ptr); Index: ossp-pkg/uuid/php/uuid.c RCS File: /v/ossp/cvs/ossp-pkg/uuid/php/Attic/uuid.c,v rcsdiff -q -kk '-r1.5' '-r1.6' -u '/v/ossp/cvs/ossp-pkg/uuid/php/Attic/uuid.c,v' 2>/dev/null --- uuid.c 2006/02/07 08:19:16 1.5 +++ uuid.c 2006/05/11 09:37:30 1.6 @@ -70,6 +70,7 @@ REGISTER_LONG_CONSTANT("UUID_VERSION", UUID_VERSION, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("UUID_LEN_BIN", UUID_LEN_BIN, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("UUID_LEN_STR", UUID_LEN_STR, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("UUID_LEN_SIV", UUID_LEN_SIV, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("UUID_RC_OK", UUID_RC_OK, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("UUID_RC_ARG", UUID_RC_ARG, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("UUID_RC_MEM", UUID_RC_MEM, CONST_CS|CONST_PERSISTENT); @@ -83,6 +84,7 @@ REGISTER_LONG_CONSTANT("UUID_MAKE_MC", UUID_MAKE_MC, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("UUID_FMT_BIN", UUID_FMT_BIN, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("UUID_FMT_STR", UUID_FMT_STR, CONST_CS|CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("UUID_FMT_SIV", UUID_FMT_SIV, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("UUID_FMT_TXT", UUID_FMT_TXT, CONST_CS|CONST_PERSISTENT); return SUCCESS; Index: ossp-pkg/uuid/uuid++.cc RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid++.cc,v rcsdiff -q -kk '-r1.5' '-r1.6' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid++.cc,v' 2>/dev/null --- uuid++.cc 2006/01/13 06:44:30 1.5 +++ uuid++.cc 2006/05/11 09:37:27 1.6 @@ -243,12 +243,13 @@ return; } -/* method: import string representation */ +/* method: import string or single integer value representation */ void uuid::import(const char *str) { uuid_rc_t rc; if ((rc = uuid_import(ctx, UUID_FMT_STR, str, UUID_LEN_STR)) != UUID_RC_OK) - throw uuid_error_t(rc); + if ((rc = uuid_import(ctx, UUID_FMT_SIV, str, UUID_LEN_SIV)) != UUID_RC_OK) + throw uuid_error_t(rc); return; } @@ -271,6 +272,16 @@ throw uuid_error_t(rc); return str; } + +/* method: export single integer value representation */ +char *uuid::integer(void) +{ + uuid_rc_t rc; + char *str = NULL; + if ((rc = uuid_export(ctx, UUID_FMT_SIV, (void **)&str, NULL)) != UUID_RC_OK) + throw uuid_error_t(rc); + return str; +} /* method: export textual summary representation */ char *uuid::summary(void) Index: ossp-pkg/uuid/uuid++.hh RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid++.hh,v rcsdiff -q -kk '-r1.3' '-r1.4' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid++.hh,v' 2>/dev/null --- uuid++.hh 2006/01/13 06:44:30 1.3 +++ uuid++.hh 2006/05/11 09:37:27 1.4 @@ -71,6 +71,7 @@ void import (const char *_str); /* regular method */ void *binary (void); /* regular method */ char *string (void); /* regular method */ + char *integer (void); /* regular method */ char *summary (void); /* regular method */ unsigned long version (void); /* regular method */ Index: ossp-pkg/uuid/uuid++.pod RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid++.pod,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid++.pod,v' 2>/dev/null --- uuid++.pod 2006/01/13 06:44:30 1.2 +++ uuid++.pod 2006/05/11 09:37:28 1.3 @@ -115,7 +115,7 @@ =item uuid &B(const char *_str); -The assignment operator corresponding to the import constructor for string representation. +The assignment operator corresponding to the import constructor for string and single integer value representation. =item uuid B(void); @@ -177,6 +177,10 @@ Regular method corresponding to the C API function B for string representation usage. +=item char *B(void); + +Regular method corresponding to the C API function B for single integer value representation usage. + =item char *B(void); Regular method corresponding to the C API function B for textual summary representation usage. Index: ossp-pkg/uuid/uuid.c RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid.c,v rcsdiff -q -kk '-r1.58' '-r1.59' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid.c,v' 2>/dev/null --- uuid.c 2006/02/07 08:19:15 1.58 +++ uuid.c 2006/05/11 09:37:28 1.59 @@ -50,6 +50,7 @@ #include "uuid_prng.h" #include "uuid_mac.h" #include "uuid_ui64.h" +#include "uuid_ui128.h" #include "uuid_str.h" #include "uuid_bm.h" #include "uuid_ac.h" @@ -431,6 +432,39 @@ return UUID_RC_OK; } +/* INTERNAL: import UUID object from single integer value representation */ +static uuid_rc_t uuid_import_siv(uuid_t *uuid, const void *data_ptr, size_t data_len) +{ + const char *str; + uuid_uint8_t tmp_bin[UUID_LEN_BIN]; + ui128_t ui, ui2; + int i; + + /* sanity check argument(s) */ + if (uuid == NULL || data_ptr == NULL || data_len < 1) + return UUID_RC_ARG; + + /* check for correct UUID single integer value syntax */ + str = (const char *)data_ptr; + for (i = 0; i < data_len; i++) + if (!isdigit((int)str[i])) + return UUID_RC_ARG; + + /* parse single integer value representation (SIV) */ + ui = ui128_s2i(str, NULL, 10); + + /* import octets into UUID binary representation */ + for (i = 0; i < UUID_LEN_BIN; i++) { + ui = ui128_rol(ui, 8, &ui2); + tmp_bin[i] = (uuid_uint8_t)(ui128_i2n(ui2) & 0xff); + } + + /* import into internal UUID representation */ + uuid_import(uuid, UUID_FMT_BIN, (void *)&tmp_bin, UUID_LEN_BIN); + + return UUID_RC_OK; +} + /* INTERNAL: export UUID object to string representation */ static uuid_rc_t uuid_export_str(const uuid_t *uuid, void **data_ptr, size_t *data_len) { @@ -482,6 +516,61 @@ return UUID_RC_OK; } +/* INTERNAL: export UUID object to single integer value representation */ +static uuid_rc_t uuid_export_siv(const uuid_t *uuid, void **data_ptr, size_t *data_len) +{ + char *data_buf; + void *tmp_ptr; + size_t tmp_len; + uuid_uint8_t tmp_bin[UUID_LEN_BIN]; + ui128_t ui, ui2; + uuid_rc_t rc; + int i; + + /* sanity check argument(s) */ + if (uuid == NULL || data_ptr == NULL) + return UUID_RC_ARG; + + /* determine output buffer */ + if (*data_ptr == NULL) { + if ((data_buf = (char *)malloc(UUID_LEN_SIV+1)) == NULL) + return UUID_RC_MEM; + if (data_len != NULL) + *data_len = UUID_LEN_SIV+1; + } + else { + data_buf = (char *)(*data_ptr); + if (data_len == NULL) + return UUID_RC_ARG; + if (*data_len < UUID_LEN_SIV+1) + return UUID_RC_MEM; + *data_len = UUID_LEN_SIV+1; + } + + /* export into UUID binary representation */ + tmp_ptr = (void *)&tmp_bin; + tmp_len = sizeof(tmp_bin); + if ((rc = uuid_export(uuid, UUID_FMT_BIN, &tmp_ptr, &tmp_len)) != UUID_RC_OK) + return rc; + + /* import from UUID binary representation */ + ui = ui128_zero(); + for (i = 0; i < UUID_LEN_BIN; i++) { + ui2 = ui128_n2i((unsigned long)tmp_bin[i]); + ui = ui128_rol(ui, 8, NULL); + ui = ui128_or(ui, ui2); + } + + /* format into single integer value representation */ + ui128_i2s(ui, data_buf, UUID_LEN_SIV+1, 10); + + /* pass back new buffer if locally allocated */ + if (*data_ptr == NULL) + *data_ptr = data_buf; + + return UUID_RC_OK; +} + /* decoding tables */ static struct { uuid_uint8_t num; @@ -518,6 +607,7 @@ uuid_uint32_t tmp32; uuid_uint8_t tmp_bin[UUID_LEN_BIN]; char tmp_str[UUID_LEN_STR+1]; + char tmp_siv[UUID_LEN_SIV+1]; void *tmp_ptr; size_t tmp_len; ui64_t t; @@ -541,12 +631,17 @@ if ((rc = uuid_isnil(uuid, &isnil)) != UUID_RC_OK) return rc; - /* decode into string representation */ + /* decode into various representations */ tmp_ptr = (void *)&tmp_str; tmp_len = sizeof(tmp_str); if ((rc = uuid_export(uuid, UUID_FMT_STR, &tmp_ptr, &tmp_len)) != UUID_RC_OK) return rc; - str_rsprintf(out, "UUID: %s\n", tmp_str); + tmp_ptr = (void *)&tmp_siv; + tmp_len = sizeof(tmp_siv); + if ((rc = uuid_export(uuid, UUID_FMT_SIV, &tmp_ptr, &tmp_len)) != UUID_RC_OK) + return rc; + str_rsprintf(out, "encode: STR: %s\n", tmp_str); + str_rsprintf(out, " SIV: %s\n", tmp_siv); /* decode UUID variant */ tmp8 = uuid->obj.clock_seq_hi_and_reserved; @@ -567,7 +662,7 @@ } } } - str_rsprintf(out, "variant: %s\n", variant); + str_rsprintf(out, "decode: variant: %s\n", variant); /* decode UUID version */ tmp16 = (BM_SHR(uuid->obj.time_hi_and_version, 12) & BM_MASK(3,0)); @@ -582,7 +677,7 @@ } } } - str_rsprintf(out, "version: %d (%s)\n", (int)tmp16, version); + str_rsprintf(out, " version: %d (%s)\n", (int)tmp16, version); /* * decode UUID content @@ -602,15 +697,15 @@ t_sec = (time_t)ui64_i2n(t); tm = gmtime(&t_sec); strftime(t_buf, sizeof(t_buf), "%Y-%m-%d %H:%M:%S", tm); - str_rsprintf(out, "content: time: %s.%06d.%d UTC\n", t_buf, t_usec, t_nsec); + str_rsprintf(out, " content: time: %s.%06d.%d UTC\n", t_buf, t_usec, t_nsec); /* decode clock sequence */ tmp32 = ((uuid->obj.clock_seq_hi_and_reserved & BM_MASK(5,0)) << 8) + uuid->obj.clock_seq_low; - str_rsprintf(out, " clock: %ld (usually random)\n", (long)tmp32); + str_rsprintf(out, " clock: %ld (usually random)\n", (long)tmp32); /* decode node MAC address */ - str_rsprintf(out, " node: %02x:%02x:%02x:%02x:%02x:%02x (%s %s)\n", + str_rsprintf(out, " node: %02x:%02x:%02x:%02x:%02x:%02x (%s %s)\n", (unsigned int)uuid->obj.node[0], (unsigned int)uuid->obj.node[1], (unsigned int)uuid->obj.node[2], @@ -646,8 +741,8 @@ /* dump as colon-seperated hexadecimal byte-string */ str_rsprintf(out, - "content: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n" - " (%s)\n", + " content: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n" + " (%s)\n", (unsigned int)tmp_bin[0], (unsigned int)tmp_bin[1], (unsigned int)tmp_bin[2], (unsigned int)tmp_bin[3], (unsigned int)tmp_bin[4], (unsigned int)tmp_bin[5], (unsigned int)tmp_bin[6], (unsigned int)tmp_bin[7], (unsigned int)tmp_bin[8], @@ -687,6 +782,7 @@ switch (fmt) { case UUID_FMT_BIN: rc = uuid_import_bin(uuid, data_ptr, data_len); break; case UUID_FMT_STR: rc = uuid_import_str(uuid, data_ptr, data_len); break; + case UUID_FMT_SIV: rc = uuid_import_siv(uuid, data_ptr, data_len); break; case UUID_FMT_TXT: rc = UUID_RC_IMP; /* not implemented */ break; default: rc = UUID_RC_ARG; } @@ -707,6 +803,7 @@ switch (fmt) { case UUID_FMT_BIN: rc = uuid_export_bin(uuid, data_ptr, data_len); break; case UUID_FMT_STR: rc = uuid_export_str(uuid, data_ptr, data_len); break; + case UUID_FMT_SIV: rc = uuid_export_siv(uuid, data_ptr, data_len); break; case UUID_FMT_TXT: rc = uuid_export_txt(uuid, data_ptr, data_len); break; default: rc = UUID_RC_ARG; } Index: ossp-pkg/uuid/uuid.h.in RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid.h.in,v rcsdiff -q -kk '-r1.11' '-r1.12' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid.h.in,v' 2>/dev/null --- uuid.h.in 2006/02/07 08:19:15 1.11 +++ uuid.h.in 2006/05/11 09:37:28 1.12 @@ -60,6 +60,7 @@ /* encoding octet stream lengths */ #define UUID_LEN_BIN (128 /*bit*/ / 8 /*bytes*/) #define UUID_LEN_STR (128 /*bit*/ / 4 /*nibbles*/ + 4 /*hyphens*/) +#define UUID_LEN_SIV (39 /*int(log(10,exp(2,128)-1)+1) digits*/) /* API return codes */ typedef enum { @@ -84,7 +85,8 @@ typedef enum { UUID_FMT_BIN = 0, /* binary representation (import/export) */ UUID_FMT_STR = 1, /* string representation (import/export) */ - UUID_FMT_TXT = 2 /* textual description (export only) */ + UUID_FMT_SIV = 2, /* single integer value (import/export) */ + UUID_FMT_TXT = 3 /* textual description (export only) */ } uuid_fmt_t; /* UUID abstract data type */ Index: ossp-pkg/uuid/uuid.pod RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid.pod,v rcsdiff -q -kk '-r1.36' '-r1.37' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid.pod,v' 2>/dev/null --- uuid.pod 2006/05/10 08:53:11 1.36 +++ uuid.pod 2006/05/11 09:37:28 1.37 @@ -77,11 +77,11 @@ 3| node (2-5) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -An example of a UUID binary representation is the octet stream "C<0xEC -0xB9 0xF3 0x5F 0x44 0x2A 0x11 0xD8 0x8A 0x24 0x00 0x90 0x27 0x2F 0xF7 -0x25>". The binary representation format is exactly what the B API functions B() and B() deal with -under C. +An example of a UUID binary representation is the octet stream C<0xF8 +0x1D 0x4F 0xAE 0x7D 0xEC 0x11 0xD0 0xA7 0x65 0x00 0xA0 0xC9 0x1E 0x6B +0xF6>. The binary representation format is exactly what the B +API functions B() and B() deal with under +C. =head2 UUID ASCII String Representation @@ -110,10 +110,32 @@ |"A"|"B"|"C"|"D"|"E"|"F" An example of a UUID string representation is the ASCII string -"C<54531d28-402b-11d8-af12-0002a5094c23>". The string representation +"C". The string representation format is exactly what the B API functions B() and B() deal with under C. +Notice: a corresponding URL can be generated out of a ASCII string +representation of an UUID by prefixing with "C" as in +"C". + +=head2 UUID Single Integer Value Representation + +According to the ISO/IEC 11578:1996 and ITU-T Rec. X.667 standards, a +DCE 1.1 variant UUID can be also represented as a single integer value +consisting of a decimal number with up to 39 digits. + +An example of a UUID single integer value representation is the decimal +number "C<329800735698586629295641978511506172918>". The string +representation format is exactly what the B API functions +B() and B() deal with under C. + +Notice: a corresponding ISO OID can be generated under the +"{joint-iso-itu-t(2) uuid(25)}" arc out of a single integer value +representation of a UUID by prefixing with "C<2.25.>". An example OID +is "C<2.25.329800735698586629295641978511506172918>". Additionally, +an URL can be generated by further prefixing with "C" as in +"C". + =head2 UUID Variants and Versions A UUID has a variant and version. The variant defines the layout of the @@ -205,11 +227,13 @@ $I, {qw(s 9 . 2 b 1 a 0)}->{$I}, ($I eq 's' ? 99 : $I))", i.e., the version 0.9.6 is encoded as "0x009206". -=item B, B +=item B, B, B The number of octets of the UUID binary and string representations. -Notice that the lengths of the string representation does I include -the necessary C termination character. +Notice that the lengths of the string representation (B) +and the lengths of the single integer value representation +(B) does I include the necessary C termination +character. =item B, B, B, B, B @@ -224,13 +248,15 @@ The C indicates success, the others indicate errors. Use B() to translate them into string versions. -=item B, B, B +=item B, B, B, B The I formats for use with B() and B(). The B indicates the UUID binary representation (of length B), the B indicates the UUID string -representation (of length B) and the B -indicates the textual description (of arbitrary length) of a UUID. +representation (of length B), the B +indicates the UUID single integer value representation (of maximum +length B) and the B indicates the textual +description (of arbitrary length) of a UUID. =back @@ -276,7 +302,7 @@ The format of the external representation is specified by I and the minimum expected length in I depends on it. Valid values for -I are B and B. +I are B, B and B. =item uuid_rc_t B(const uuid_t *I, uuid_fmt_t I, void **I, size_t *I); @@ -291,7 +317,8 @@ The format of the external representation is specified by I and the minimum required length in C<*>I depends on it. Valid values -for I are B, B and B. +for I are B, B, B and +B. =item uuid_rc_t B(uuid_t *I, const char *I); Index: ossp-pkg/uuid/uuid_cli.c RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_cli.c,v rcsdiff -q -kk '-r1.21' '-r1.22' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_cli.c,v' 2>/dev/null --- uuid_cli.c 2006/02/07 08:19:15 1.21 +++ uuid_cli.c 2006/05/11 09:37:28 1.22 @@ -62,8 +62,8 @@ vfprintf(stderr, str, ap); fprintf(stderr, "\n"); } - fprintf(stderr, "usage: uuid [-v version] [-m] [-n count] [-1] [-r] [-o filename] [namespace name]\n"); - fprintf(stderr, "usage: uuid -d [-r] [-o filename] [uuid]\n"); + fprintf(stderr, "usage: uuid [-v version] [-m] [-n count] [-1] [-F format] [-o filename] [namespace name]\n"); + fprintf(stderr, "usage: uuid -d [-F format] [-o filename] [uuid]\n"); va_end(ap); exit(1); } @@ -73,6 +73,7 @@ { char uuid_buf_bin[UUID_LEN_BIN]; char uuid_buf_str[UUID_LEN_STR+1]; + char uuid_buf_siv[UUID_LEN_SIV+1]; uuid_t *uuid; uuid_t *uuid_ns; uuid_rc_t rc; @@ -82,20 +83,20 @@ int count; int i; int iterate; - int raw; + uuid_fmt_t fmt; int decode; void *vp; size_t n; unsigned int version; /* command line parsing */ - count = -1; /* no count yet */ - fp = stdout; /* default output file */ - iterate = 0; /* not one at a time */ - raw = 0; /* default is ASCII output */ - decode = 0; /* default is to encode */ + count = -1; /* no count yet */ + fp = stdout; /* default output file */ + iterate = 0; /* not one at a time */ + fmt = UUID_FMT_STR; /* default is ASCII output */ + decode = 0; /* default is to encode */ version = UUID_MAKE_V1; - while ((ch = getopt(argc, argv, "1n:rdmo:v:h")) != -1) { + while ((ch = getopt(argc, argv, "1n:rF:dmo:v:h")) != -1) { switch (ch) { case '1': iterate = 1; @@ -108,7 +109,17 @@ usage("invalid argument to option 'n'"); break; case 'r': - raw = 1; + fmt = UUID_FMT_BIN; + break; + case 'F': + if (strcasecmp(optarg, "bin") == 0) + fmt = UUID_FMT_BIN; + else if (strcasecmp(optarg, "str") == 0) + fmt = UUID_FMT_STR; + else if (strcasecmp(optarg, "siv") == 0) + fmt = UUID_FMT_SIV; + else + error(1, "invalid format \"%s\" (has to be \"bin\", \"str\" or \"siv\")", optarg); break; case 'd': decode = 1; @@ -155,27 +166,39 @@ if (argc != 1) usage("invalid number of arguments"); if (strcmp(argv[0], "-") == 0) { - if (raw) { + if (fmt == UUID_FMT_BIN) { if (fread(uuid_buf_bin, UUID_LEN_BIN, 1, stdin) != 1) error(1, "fread: failed to read %d (UUID_LEN_BIN) bytes from stdin", UUID_LEN_BIN); if ((rc = uuid_import(uuid, UUID_FMT_BIN, uuid_buf_bin, UUID_LEN_BIN)) != UUID_RC_OK) error(1, "uuid_import: %s", uuid_error(rc)); } - else { + else if (fmt == UUID_FMT_STR) { if (fread(uuid_buf_str, UUID_LEN_STR, 1, stdin) != 1) error(1, "fread: failed to read %d (UUID_LEN_STR) bytes from stdin", UUID_LEN_STR); uuid_buf_str[UUID_LEN_STR] = '\0'; if ((rc = uuid_import(uuid, UUID_FMT_STR, uuid_buf_str, UUID_LEN_STR)) != UUID_RC_OK) error(1, "uuid_import: %s", uuid_error(rc)); } + else if (fmt == UUID_FMT_SIV) { + if (fread(uuid_buf_siv, UUID_LEN_SIV, 1, stdin) != 1) + error(1, "fread: failed to read %d (UUID_LEN_SIV) bytes from stdin", UUID_LEN_SIV); + uuid_buf_siv[UUID_LEN_SIV] = '\0'; + if ((rc = uuid_import(uuid, UUID_FMT_SIV, uuid_buf_siv, UUID_LEN_SIV)) != UUID_RC_OK) + error(1, "uuid_import: %s", uuid_error(rc)); + } } else { - if (raw) - error(1, "raw input mode only possible if reading from stdin"); - if (strlen(argv[0]) != UUID_LEN_STR) - error(1, "invalid length of UUID string representation"); - if ((rc = uuid_import(uuid, UUID_FMT_STR, argv[0], strlen(argv[0]))) != UUID_RC_OK) - error(1, "uuid_import: %s", uuid_error(rc)); + if (fmt == UUID_FMT_BIN) { + error(1, "binary input mode only possible if reading from stdin"); + } + else if (fmt == UUID_FMT_STR) { + if ((rc = uuid_import(uuid, UUID_FMT_STR, argv[0], strlen(argv[0]))) != UUID_RC_OK) + error(1, "uuid_import: %s", uuid_error(rc)); + } + else if (fmt == UUID_FMT_SIV) { + if ((rc = uuid_import(uuid, UUID_FMT_SIV, argv[0], strlen(argv[0]))) != UUID_RC_OK) + error(1, "uuid_import: %s", uuid_error(rc)); + } } vp = NULL; if ((rc = uuid_export(uuid, UUID_FMT_TXT, &vp, NULL)) != UUID_RC_OK) @@ -222,19 +245,26 @@ if ((rc = uuid_make(uuid, version)) != UUID_RC_OK) error(1, "uuid_make: %s", uuid_error(rc)); } - if (raw) { + if (fmt == UUID_FMT_BIN) { vp = NULL; if ((rc = uuid_export(uuid, UUID_FMT_BIN, &vp, &n)) != UUID_RC_OK) error(1, "uuid_export: %s", uuid_error(rc)); fwrite(vp, n, 1, fp); free(vp); } - else { + else if (fmt == UUID_FMT_STR) { vp = NULL; if ((rc = uuid_export(uuid, UUID_FMT_STR, &vp, &n)) != UUID_RC_OK) error(1, "uuid_export: %s", uuid_error(rc)); fprintf(fp, "%s\n", (char *)vp); free(vp); + } + else if (fmt == UUID_FMT_SIV) { + vp = NULL; + if ((rc = uuid_export(uuid, UUID_FMT_SIV, &vp, &n)) != UUID_RC_OK) + error(1, "uuid_export: %s", uuid_error(rc)); + fprintf(fp, "%s\n", (char *)vp); + free(vp); } } if ((rc = uuid_destroy(uuid)) != UUID_RC_OK) Index: ossp-pkg/uuid/uuid_cli.pod RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_cli.pod,v rcsdiff -q -kk '-r1.24' '-r1.25' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_cli.pod,v' 2>/dev/null --- uuid_cli.pod 2006/01/13 06:44:30 1.24 +++ uuid_cli.pod 2006/05/11 09:37:28 1.25 @@ -44,7 +44,7 @@ [B<-m>] [B<-n> I] [B<-1>] -[B<-r>] +[B<-F> I] [B<-o> I] [I I] @@ -113,11 +113,31 @@ remembered in the UUID context of the API. Option B<-1> deletes the remembered UUID on each iteration. -=item B<-r> +=item B<-F> I + +Representation format for importing or exporting an UUID. The +following (case insensitive) format identifiers are currently recognized: + +=over 4 + +=item C (binary representation) + +This is the raw 128 bit network byte order binary representation of a +UUID. Example is the octet stream C<0xF8 0x1D 0x4F 0xAE 0x7D 0xEC 0x11 +0xD0 0xA7 0x65 0x00 0xA0 0xC9 0x1E 0x6B 0xF6>. -Output the generated UUID in 128 bit (network byte order) raw binary -representation format. The default is to output the generated UUID in -the standardized ASCII string representation. +=item C (string representation) + +This is the 36 character hexadecimal ASCII string representation of a +UUID. Example is the string "C". + +=item C (single integer value representation) + +This is the maximum 39 character long single integer +value representation of a UUID. Example is the string +"C<329800735698586629295641978511506172918>". + +=back =item B<-o> I @@ -139,12 +159,13 @@ # decode and dump DCE 1.1 v1 UUID (time and node based) $ uuid -d 01c47915-4777-11d8-bc70-0090272ff725 - UUID: 01c47915-4777-11d8-bc70-0090272ff725 - variant: DCE 1.1, ISO/IEC 11578:1996 - version: 1 (time and node based) - content: time: 2004-01-15 16:22:26.376322.1 UTC - clock: 15472 (usually random) - node: 00:90:27:2f:f7:25 (global unicast) + encode: STR: 01c47915-4777-11d8-bc70-0090272ff725 + SIV: 2349374037528578887923094374772111141 + decode: variant: DCE 1.1, ISO/IEC 11578:1996 + version: 1 (time and node based) + content: time: 2004-01-15 16:22:26.376322.1 UTC + clock: 15472 (usually random) + node: 00:90:27:2f:f7:25 (global unicast) # generate DCE 1.1 v3 UUID (name based) $ uuid -v3 ns:URL http://www.ossp.org/ @@ -152,11 +173,12 @@ # decode and dump DCE 1.1 v3 UUID (name based) $ uuid -d 02d9e6d5-9467-382e-8f9b-9300a64ac3cd - UUID: 02d9e6d5-9467-382e-8f9b-9300a64ac3cd - variant: DCE 1.1, ISO/IEC 11578:1996 - version: 3 (name based) - content: 02:D9:E6:D5:94:67:08:2E:0F:9B:93:00:A6:4A:C3:CD - (not decipherable, because message digest only) + encode: STR: 02d9e6d5-9467-382e-8f9b-9300a64ac3cd + SIV: 3789866285607910888100818383505376205 + decode: variant: DCE 1.1, ISO/IEC 11578:1996 + version: 3 (name based, MD5) + content: 02:D9:E6:D5:94:67:08:2E:0F:9B:93:00:A6:4A:C3:CD + (not decipherable: MD5 message digest only) # generate DCE 1.1 v4 UUID 4 (random data based) $ uuid -v4 @@ -164,11 +186,12 @@ # decode and dump DCE 1.1 v4 UUID 4 (random data based) $ uuid -d eb424026-6f54-4ef8-a4d0-bb658a1fc6cf - UUID: eb424026-6f54-4ef8-a4d0-bb658a1fc6cf - variant: DCE 1.1, ISO/IEC 11578:1996 - version: 4 (random data based) - content: EB:42:40:26:6F:54:0E:F8:24:D0:BB:65:8A:1F:C6:CF - (no semantics, because random data only) + encode: STR: eb424026-6f54-4ef8-a4d0-bb658a1fc6cf + SIV: 312712571721458096795100956955942831823 + decode: variant: DCE 1.1, ISO/IEC 11578:1996 + version: 4 (random data based) + content: EB:42:40:26:6F:54:0E:F8:24:D0:BB:65:8A:1F:C6:CF + (no semantics: random data only) =head1 SEE ALSO Index: ossp-pkg/uuid/uuid_ui128.c RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_ui128.c,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_ui128.c,v' | diff -u /dev/null - -L'ossp-pkg/uuid/uuid_ui128.c' 2>/dev/null --- ossp-pkg/uuid/uuid_ui128.c +++ - 2024-05-09 10:46:25.040985927 +0200 @@ -0,0 +1,586 @@ +/* +** OSSP ui128 - 128-Bit Arithmetic +** Copyright (c) 2002-2005 Ralf S. Engelschall +** Copyright (c) 2002-2005 The OSSP Project +** +** This file is part of OSSP ui128, a 128-bit arithmetic library +** which can be found at http://www.ossp.org/pkg/lib/ui128/. +** +** Permission to use, copy, modify, and distribute this software for +** any purpose with or without fee is hereby granted, provided that +** the above copyright notice and this permission notice appear in all +** copies. +** +** 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 THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR +** 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. +** +** ui128.c: implementation of 128-bit unsigned integer arithmetic +*/ + +#include +#include + +#include "uuid_ui128.h" + +#define UI128_BASE 256 /* 2^8 */ +#define UI128_DIGITS 16 /* 8*16 = 128 bit */ +#define UIXX_T(n) struct { unsigned char x[n]; } + +/* fill an ui128_t with a sequence of a particular digit */ +#define ui128_fill(__x, __n) \ + /*lint -save -e717*/ \ + do { int __i; \ + for (__i = 0; __i < UI128_DIGITS; __i++) \ + (__x).x[__i] = (__n); \ + } while (0) \ + /*lint -restore*/ + +/* the value zero */ +ui128_t ui128_zero(void) +{ + ui128_t z; + + ui128_fill(z, 0); + return z; +} + +/* the maximum value */ +ui128_t ui128_max(void) +{ + ui128_t z; + + ui128_fill(z, UI128_BASE-1); + return z; +} + +/* convert ISO-C "unsigned long" into internal format */ +ui128_t ui128_n2i(unsigned long n) +{ + ui128_t z; + int i; + + i = 0; + do { + z.x[i++] = (n % UI128_BASE); + } while ((n /= UI128_BASE) > 0 && i < UI128_DIGITS); + for ( ; i < UI128_DIGITS; i++) + z.x[i] = 0; + return z; +} + +/* convert internal format into ISO-C "unsigned long"; + truncates if sizeof(unsigned long) is less than UI128_DIGITS! */ +unsigned long ui128_i2n(ui128_t x) +{ + unsigned long n; + int i; + + n = 0; + i = (int)sizeof(n); + /*lint -save -e774*/ + if (i > UI128_DIGITS) + i = UI128_DIGITS; + /*lint -restore*/ + while (--i >= 0) { + n = (n * UI128_BASE) + x.x[i]; + } + return n; +} + +/* convert string representation of arbitrary base into internal format */ +ui128_t ui128_s2i(const char *str, char **end, int base) +{ + ui128_t z; + const char *cp; + int carry; + static char map[] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 0...9 */ + 36, 36, 36, 36, 36, 36, 36, /* illegal chars */ + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, /* A...M */ + 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, /* N...Z */ + 36, 36, 36, 36, 36, 36, /* illegal chars */ + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, /* a...m */ + 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35 /* m...z */ + }; + + ui128_fill(z, 0); + if (str == NULL || (base < 2 || base > 36)) + return z; + cp = str; + while (*cp != '\0' && isspace((int)(*cp))) + cp++; + while ( *cp != '\0' + && isalnum((int)(*cp)) + && map[(int)(*cp)-'0'] < base) { + z = ui128_muln(z, base, &carry); + if (carry) + break; + z = ui128_addn(z, map[(int)(*cp)-'0'], &carry); + if (carry) + break; + cp++; + } + if (end != NULL) + *end = (char *)cp; + return z; +} + +/* convert internal format into string representation of arbitrary base */ +char *ui128_i2s(ui128_t x, char *str, size_t len, int base) +{ + static char map[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + char c; + int r; + int n; + int i, j; + + if (str == NULL || len < 2 || (base < 2 || base > 36)) + return NULL; + n = ui128_len(x); + i = 0; + do { + x = ui128_divn(x, base, &r); + str[i++] = map[r]; + while (n > 1 && x.x[n-1] == 0) + n--; + } while (i < ((int)len-1) && (n > 1 || x.x[0] != 0)); + str[i] = '\0'; + for (j = 0; j < --i; j++) { + c = str[j]; + str[j] = str[i]; + str[i] = c; + } + return str; +} + +/* addition of two ui128_t */ +ui128_t ui128_add(ui128_t x, ui128_t y, ui128_t *ov) +{ + ui128_t z; + int carry; + int i; + + carry = 0; + for (i = 0; i < UI128_DIGITS; i++) { + carry += (x.x[i] + y.x[i]); + z.x[i] = (carry % UI128_BASE); + carry /= UI128_BASE; + } + if (ov != NULL) + *ov = ui128_n2i((unsigned long)carry); + return z; +} + +/* addition of an ui128_t and a single digit */ +ui128_t ui128_addn(ui128_t x, int y, int *ov) +{ + ui128_t z; + int i; + + for (i = 0; i < UI128_DIGITS; i++) { + y += x.x[i]; + z.x[i] = (y % UI128_BASE); + y /= UI128_BASE; + } + if (ov != NULL) + *ov = y; + return z; +} + +/* subtraction of two ui128_t */ +ui128_t ui128_sub(ui128_t x, ui128_t y, ui128_t *ov) +{ + ui128_t z; + int borrow; + int i; + int d; + + borrow = 0; + for (i = 0; i < UI128_DIGITS; i++) { + d = ((x.x[i] + UI128_BASE) - borrow - y.x[i]); + z.x[i] = (d % UI128_BASE); + borrow = (1 - (d/UI128_BASE)); + } + if (ov != NULL) + *ov = ui128_n2i((unsigned long)borrow); + return z; +} + +/* subtraction of an ui128_t and a single digit */ +ui128_t ui128_subn(ui128_t x, int y, int *ov) +{ + ui128_t z; + int i; + int d; + + for (i = 0; i < UI128_DIGITS; i++) { + d = (x.x[i] + UI128_BASE) - y; + z.x[i] = (d % UI128_BASE); + y = (1 - (d/UI128_BASE)); + } + if (ov != NULL) + *ov = y; + return z; +} + +/* + 7 3 2 + * 9 4 2 8 + --------- + 5 8 5 6 + + 1 4 6 4 + + 2 9 2 8 + + 6 5 8 8 + --------------- + = 6 9 0 1 2 9 6 +*/ + +ui128_t ui128_mul(ui128_t x, ui128_t y, ui128_t *ov) +{ + UIXX_T(UI128_DIGITS+UI128_DIGITS) zx; + ui128_t z; + int carry; + int i, j; + + /* clear temporary result buffer */ + for (i = 0; i < (UI128_DIGITS+UI128_DIGITS); i++) + zx.x[i] = 0; + + /* perform multiplication operation */ + for (i = 0; i < UI128_DIGITS; i++) { + /* calculate partial product and immediately add to z */ + carry = 0; + for (j = 0; j < UI128_DIGITS; j++) { + carry += (x.x[i] * y.x[j]) + zx.x[i+j]; + zx.x[i+j] = (carry % UI128_BASE); + carry /= UI128_BASE; + } + /* add carry to remaining digits in z */ + for ( ; j < UI128_DIGITS + UI128_DIGITS - i; j++) { + carry += zx.x[i+j]; + zx.x[i+j] = (carry % UI128_BASE); + carry /= UI128_BASE; + } + } + + /* provide result by splitting zx into z and ov */ + memcpy(z.x, zx.x, UI128_DIGITS); + if (ov != NULL) + memcpy((*ov).x, &zx.x[UI128_DIGITS], UI128_DIGITS); + + return z; +} + +ui128_t ui128_muln(ui128_t x, int y, int *ov) +{ + ui128_t z; + int carry; + int i; + + carry = 0; + for (i = 0; i < UI128_DIGITS; i++) { + carry += (x.x[i] * y); + z.x[i] = (carry % UI128_BASE); + carry /= UI128_BASE; + } + if (ov != NULL) + *ov = carry; + return z; +} + +/* + = 2078 [q] + 0615367 [x] : 296 [y] + -0592 [dq] + ----- + = 0233 + -0000 [dq] + ----- + = 2336 + -2072 [dq] + ----- + = 2647 + -2308 [dq] + ----- + = 279 [r] + */ +ui128_t ui128_div(ui128_t x, ui128_t y, ui128_t *ov) +{ + ui128_t q; + ui128_t r; + int i; + int n, m; + int ovn; + + /* determine actual number of involved digits */ + n = ui128_len(x); + m = ui128_len(y); + + if (m == 1) { + /* simple case #1: reduceable to ui128_divn() */ + if (y.x[0] == 0) { + /* error case: division by zero! */ + ui128_fill(q, 0); + ui128_fill(r, 0); + } + else { + q = ui128_divn(x, y.x[0], &ovn); + ui128_fill(r, 0); + r.x[0] = (unsigned char)ovn; + } + + } else if (n < m) { + /* simple case #2: everything is in the remainder */ + ui128_fill(q, 0); + r = x; + + } else { /* n >= m, m > 1 */ + /* standard case: x[0..n] / y[0..m] */ + UIXX_T(UI128_DIGITS+1) rx; + UIXX_T(UI128_DIGITS+1) dq; + ui128_t t; + int km; + int k; + int qk; + unsigned long y2; + unsigned long r3; + int borrow; + int d; + + /* rx is x with a leading zero in order to make + sure that n > m and not just n >= m */ + memcpy(rx.x, x.x, UI128_DIGITS); + rx.x[UI128_DIGITS] = 0; + + for (k = n - m; k >= 0; k--) { + /* efficiently compute qk by guessing + qk := rx[k+m-2...k+m]/y[m-2...m-1] */ + km = k + m; + y2 = (y.x[m-1]*UI128_BASE) + y.x[m-2]; + r3 = (rx.x[km]*(UI128_BASE*UI128_BASE)) + + (rx.x[km-1]*UI128_BASE) + rx.x[km-2]; + qk = r3 / y2; + if (qk >= UI128_BASE) + qk = UI128_BASE - 1; + + /* dq := y*qk (post-adjust qk if guessed incorrectly) */ + t = ui128_muln(y, qk, &ovn); + memcpy(dq.x, t.x, UI128_DIGITS); + dq.x[m] = (unsigned char)ovn; + for (i = m; i > 0; i--) + if (rx.x[i+k] != dq.x[i]) + break; + if (rx.x[i+k] < dq.x[i]) { + t = ui128_muln(y, --qk, &ovn); + memcpy(dq.x, t.x, UI128_DIGITS); + dq.x[m] = (unsigned char)ovn; + } + + /* store qk */ + q.x[k] = (unsigned char)qk; + + /* rx := rx - dq*(b^k) */ + borrow = 0; + for (i = 0; i < m+1; i++) { + d = ((rx.x[k+i] + UI128_BASE) - borrow - dq.x[i]); + rx.x[k+i] = (d % UI128_BASE); + borrow = (1 - (d/UI128_BASE)); + } + } + memcpy(r.x, rx.x, m); + + /* fill out results with leading zeros */ + for (i = n-m+1; i < UI128_DIGITS; i++) + q.x[i] = 0; + for (i = m; i < UI128_DIGITS; i++) + r.x[i] = 0; + } + + /* provide results */ + if (ov != NULL) + *ov = r; + return q; +} + +ui128_t ui128_divn(ui128_t x, int y, int *ov) +{ + ui128_t z; + unsigned int carry; + int i; + + carry = 0; + for (i = (UI128_DIGITS - 1); i >= 0; i--) { + carry = (carry * UI128_BASE) + x.x[i]; + z.x[i] = (carry / y); + carry %= y; + } + if (ov != NULL) + *ov = carry; + return z; +} + +ui128_t ui128_and(ui128_t x, ui128_t y) +{ + ui128_t z; + int i; + + for (i = 0; i < UI128_DIGITS; i++) + z.x[i] = (x.x[i] & y.x[i]); + return z; +} + +ui128_t ui128_or(ui128_t x, ui128_t y) +{ + ui128_t z; + int i; + + for (i = 0; i < UI128_DIGITS; i++) + z.x[i] = (x.x[i] | y.x[i]); + return z; +} + +ui128_t ui128_xor(ui128_t x, ui128_t y) +{ + ui128_t z; + int i; + + for (i = 0; i < UI128_DIGITS; i++) + z.x[i] = ((x.x[i] & ~(y.x[i])) | (~(x.x[i]) & (y.x[i]))); + return z; +} + +ui128_t ui128_not(ui128_t x) +{ + ui128_t z; + int i; + + for (i = 0; i < UI128_DIGITS; i++) + z.x[i] = ~(x.x[i]); + return z; +} + +ui128_t ui128_rol(ui128_t x, int s, ui128_t *ov) +{ + UIXX_T(UI128_DIGITS+UI128_DIGITS) zx; + ui128_t z; + int i; + int carry; + + if (s <= 0) { + /* no shift at all */ + if (ov != NULL) + *ov = ui128_zero(); + return x; + } + else if (s > 128) { + /* too large shift */ + if (ov != NULL) + *ov = ui128_zero(); + return ui128_zero(); + } + else if (s == 128) { + /* maximum shift */ + if (ov != NULL) + *ov = x; + return ui128_zero(); + } + else { /* regular shift */ + /* shift (logically) left by s/8 bytes */ + for (i = 0; i < UI128_DIGITS+UI128_DIGITS; i++) + zx.x[i] = 0; + for (i = 0; i < UI128_DIGITS; i++) + zx.x[i+(s/8)] = x.x[i]; + /* shift (logically) left by remaining s%8 bits */ + s %= 8; + if (s > 0) { + carry = 0; + for (i = 0; i < UI128_DIGITS+UI128_DIGITS; i++) { + carry += (zx.x[i] * (1 << s)); + zx.x[i] = (carry % UI128_BASE); + carry /= UI128_BASE; + } + } + memcpy(z.x, zx.x, UI128_DIGITS); + if (ov != NULL) + memcpy((*ov).x, &zx.x[UI128_DIGITS], UI128_DIGITS); + } + return z; +} + +ui128_t ui128_ror(ui128_t x, int s, ui128_t *ov) +{ + UIXX_T(UI128_DIGITS+UI128_DIGITS) zx; + ui128_t z; + int i; + int carry; + + if (s <= 0) { + /* no shift at all */ + if (ov != NULL) + *ov = ui128_zero(); + return x; + } + else if (s > 128) { + /* too large shift */ + if (ov != NULL) + *ov = ui128_zero(); + return ui128_zero(); + } + else if (s == 128) { + /* maximum shift */ + if (ov != NULL) + *ov = x; + return ui128_zero(); + } + else { /* regular shift */ + /* shift (logically) right by s/8 bytes */ + for (i = 0; i < UI128_DIGITS+UI128_DIGITS; i++) + zx.x[i] = 0; + for (i = 0; i < UI128_DIGITS; i++) + zx.x[UI128_DIGITS+i-(s/8)] = x.x[i]; + /* shift (logically) right by remaining s%8 bits */ + s %= 8; + if (s > 0) { + carry = 0; + for (i = (UI128_DIGITS+UI128_DIGITS - 1); i >= 0; i--) { + carry = (carry * UI128_BASE) + zx.x[i]; + zx.x[i] = (carry / (1 << s)); + carry %= (1 << s); + } + } + memcpy(z.x, &zx.x[UI128_DIGITS], UI128_DIGITS); + if (ov != NULL) + memcpy((*ov).x, zx.x, UI128_DIGITS); + } + return z; +} + +int ui128_cmp(ui128_t x, ui128_t y) +{ + int i; + + i = UI128_DIGITS - 1; + while (i > 0 && x.x[i] == y.x[i]) + i--; + return (x.x[i] - y.x[i]); +} + +int ui128_len(ui128_t x) +{ + int i; + + for (i = UI128_DIGITS; i > 1 && x.x[i-1] == 0; i--) + ; + return i; +} + Index: ossp-pkg/uuid/uuid_ui128.h RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_ui128.h,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_ui128.h,v' | diff -u /dev/null - -L'ossp-pkg/uuid/uuid_ui128.h' 2>/dev/null --- ossp-pkg/uuid/uuid_ui128.h +++ - 2024-05-09 10:46:25.043818179 +0200 @@ -0,0 +1,114 @@ +/* +** OSSP ui128 - 128-Bit Arithmetic +** Copyright (c) 2002-2005 Ralf S. Engelschall +** Copyright (c) 2002-2005 The OSSP Project +** +** This file is part of OSSP ui128, a 128-bit arithmetic library +** which can be found at http://www.ossp.org/pkg/lib/ui128/. +** +** Permission to use, copy, modify, and distribute this software for +** any purpose with or without fee is hereby granted, provided that +** the above copyright notice and this permission notice appear in all +** copies. +** +** 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 THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR +** 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. +** +** ui128.h: API declaration +*/ + +#ifndef __UI128_H__ +#define __UI128_H__ + +#include + +#define UI128_PREFIX uuid_ + +/* embedding support */ +#ifdef UI128_PREFIX +#if defined(__STDC__) || defined(__cplusplus) +#define __UI128_CONCAT(x,y) x ## y +#define UI128_CONCAT(x,y) __UI128_CONCAT(x,y) +#else +#define __UI128_CONCAT(x) x +#define UI128_CONCAT(x,y) __UI128_CONCAT(x)y +#endif +#define ui128_t UI128_CONCAT(UI128_PREFIX,ui128_t) +#define ui128_zero UI128_CONCAT(UI128_PREFIX,ui128_zero) +#define ui128_max UI128_CONCAT(UI128_PREFIX,ui128_max) +#define ui128_n2i UI128_CONCAT(UI128_PREFIX,ui128_n2i) +#define ui128_i2n UI128_CONCAT(UI128_PREFIX,ui128_i2n) +#define ui128_s2i UI128_CONCAT(UI128_PREFIX,ui128_s2i) +#define ui128_i2s UI128_CONCAT(UI128_PREFIX,ui128_i2s) +#define ui128_add UI128_CONCAT(UI128_PREFIX,ui128_add) +#define ui128_addn UI128_CONCAT(UI128_PREFIX,ui128_addn) +#define ui128_sub UI128_CONCAT(UI128_PREFIX,ui128_sub) +#define ui128_subn UI128_CONCAT(UI128_PREFIX,ui128_subn) +#define ui128_mul UI128_CONCAT(UI128_PREFIX,ui128_mul) +#define ui128_muln UI128_CONCAT(UI128_PREFIX,ui128_muln) +#define ui128_div UI128_CONCAT(UI128_PREFIX,ui128_div) +#define ui128_divn UI128_CONCAT(UI128_PREFIX,ui128_divn) +#define ui128_and UI128_CONCAT(UI128_PREFIX,ui128_and) +#define ui128_or UI128_CONCAT(UI128_PREFIX,ui128_or) +#define ui128_xor UI128_CONCAT(UI128_PREFIX,ui128_xor) +#define ui128_not UI128_CONCAT(UI128_PREFIX,ui128_not) +#define ui128_rol UI128_CONCAT(UI128_PREFIX,ui128_rol) +#define ui128_ror UI128_CONCAT(UI128_PREFIX,ui128_ror) +#define ui128_len UI128_CONCAT(UI128_PREFIX,ui128_len) +#define ui128_cmp UI128_CONCAT(UI128_PREFIX,ui128_cmp) +#endif + +typedef struct { + unsigned char x[16]; /* x_0, ..., x_15 */ +} ui128_t; + +#define ui128_cons(x15,x14,x13,x12,x11,x10,x9,x8,x7,x6,x5,x4,x3,x2,x1,x0) \ + { { 0x##x0, 0x##x1, 0x##x2, 0x##x3, 0x##x4, 0x##x5, 0x##x6, 0x##x7, \ + { { 0x##x8, 0x##x9, 0x##x10, 0x##x11, 0x##x12, 0x##x13, 0x##x14, 0x##x15 } } + +/* particular values */ +extern ui128_t ui128_zero (void); +extern ui128_t ui128_max (void); + +/* import and export via ISO-C "unsigned long" */ +extern ui128_t ui128_n2i (unsigned long n); +extern unsigned long ui128_i2n (ui128_t x); + +/* import and export via ISO-C string of arbitrary base */ +extern ui128_t ui128_s2i (const char *str, char **end, int base); +extern char * ui128_i2s (ui128_t x, char *str, size_t len, int base); + +/* arithmetical operations */ +extern ui128_t ui128_add (ui128_t x, ui128_t y, ui128_t *ov); +extern ui128_t ui128_addn (ui128_t x, int y, int *ov); +extern ui128_t ui128_sub (ui128_t x, ui128_t y, ui128_t *ov); +extern ui128_t ui128_subn (ui128_t x, int y, int *ov); +extern ui128_t ui128_mul (ui128_t x, ui128_t y, ui128_t *ov); +extern ui128_t ui128_muln (ui128_t x, int y, int *ov); +extern ui128_t ui128_div (ui128_t x, ui128_t y, ui128_t *ov); +extern ui128_t ui128_divn (ui128_t x, int y, int *ov); + +/* bit operations */ +extern ui128_t ui128_and (ui128_t x, ui128_t y); +extern ui128_t ui128_or (ui128_t x, ui128_t y); +extern ui128_t ui128_xor (ui128_t x, ui128_t y); +extern ui128_t ui128_not (ui128_t x); +extern ui128_t ui128_rol (ui128_t x, int s, ui128_t *ov); +extern ui128_t ui128_ror (ui128_t x, int s, ui128_t *ov); + +/* other operations */ +extern int ui128_len (ui128_t x); +extern int ui128_cmp (ui128_t x, ui128_t y); + +#endif /* __UI128_H__ */ +