sidekick-client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/lib/ext/README +1 -0
- data/lib/ext/bunny-0.6.0/LICENSE +20 -0
- data/lib/ext/bunny-0.6.0/README.rdoc +66 -0
- data/lib/ext/bunny-0.6.0/Rakefile +24 -0
- data/lib/ext/bunny-0.6.0/bunny.gemspec +65 -0
- data/lib/ext/bunny-0.6.0/examples/simple_08.rb +30 -0
- data/lib/ext/bunny-0.6.0/examples/simple_09.rb +30 -0
- data/lib/ext/bunny-0.6.0/examples/simple_ack_08.rb +33 -0
- data/lib/ext/bunny-0.6.0/examples/simple_ack_09.rb +33 -0
- data/lib/ext/bunny-0.6.0/examples/simple_consumer_08.rb +53 -0
- data/lib/ext/bunny-0.6.0/examples/simple_consumer_09.rb +53 -0
- data/lib/ext/bunny-0.6.0/examples/simple_fanout_08.rb +39 -0
- data/lib/ext/bunny-0.6.0/examples/simple_fanout_09.rb +39 -0
- data/lib/ext/bunny-0.6.0/examples/simple_headers_08.rb +40 -0
- data/lib/ext/bunny-0.6.0/examples/simple_headers_09.rb +40 -0
- data/lib/ext/bunny-0.6.0/examples/simple_publisher_08.rb +27 -0
- data/lib/ext/bunny-0.6.0/examples/simple_publisher_09.rb +27 -0
- data/lib/ext/bunny-0.6.0/examples/simple_topic_08.rb +59 -0
- data/lib/ext/bunny-0.6.0/examples/simple_topic_09.rb +59 -0
- data/lib/ext/bunny-0.6.0/lib/bunny/channel08.rb +39 -0
- data/lib/ext/bunny-0.6.0/lib/bunny/channel09.rb +39 -0
- data/lib/ext/bunny-0.6.0/lib/bunny/client08.rb +494 -0
- data/lib/ext/bunny-0.6.0/lib/bunny/client09.rb +460 -0
- data/lib/ext/bunny-0.6.0/lib/bunny/exchange08.rb +175 -0
- data/lib/ext/bunny-0.6.0/lib/bunny/exchange09.rb +177 -0
- data/lib/ext/bunny-0.6.0/lib/bunny/queue08.rb +389 -0
- data/lib/ext/bunny-0.6.0/lib/bunny/queue09.rb +395 -0
- data/lib/ext/bunny-0.6.0/lib/bunny/subscription08.rb +85 -0
- data/lib/ext/bunny-0.6.0/lib/bunny/subscription09.rb +85 -0
- data/lib/ext/bunny-0.6.0/lib/bunny.rb +87 -0
- data/lib/ext/bunny-0.6.0/lib/qrack/channel.rb +18 -0
- data/lib/ext/bunny-0.6.0/lib/qrack/client.rb +204 -0
- data/lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol08.rb +132 -0
- data/lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol09.rb +133 -0
- data/lib/ext/bunny-0.6.0/lib/qrack/protocol/spec08.rb +823 -0
- data/lib/ext/bunny-0.6.0/lib/qrack/protocol/spec09.rb +521 -0
- data/lib/ext/bunny-0.6.0/lib/qrack/qrack08.rb +23 -0
- data/lib/ext/bunny-0.6.0/lib/qrack/qrack09.rb +23 -0
- data/lib/ext/bunny-0.6.0/lib/qrack/queue.rb +53 -0
- data/lib/ext/bunny-0.6.0/lib/qrack/subscription.rb +102 -0
- data/lib/ext/bunny-0.6.0/lib/qrack/transport/buffer08.rb +276 -0
- data/lib/ext/bunny-0.6.0/lib/qrack/transport/buffer09.rb +276 -0
- data/lib/ext/bunny-0.6.0/lib/qrack/transport/frame08.rb +112 -0
- data/lib/ext/bunny-0.6.0/lib/qrack/transport/frame09.rb +94 -0
- data/lib/ext/bunny-0.6.0/spec/spec_08/bunny_spec.rb +65 -0
- data/lib/ext/bunny-0.6.0/spec/spec_08/connection_spec.rb +12 -0
- data/lib/ext/bunny-0.6.0/spec/spec_08/exchange_spec.rb +162 -0
- data/lib/ext/bunny-0.6.0/spec/spec_08/queue_spec.rb +206 -0
- data/lib/ext/bunny-0.6.0/spec/spec_09/bunny_spec.rb +65 -0
- data/lib/ext/bunny-0.6.0/spec/spec_09/connection_spec.rb +12 -0
- data/lib/ext/bunny-0.6.0/spec/spec_09/exchange_spec.rb +162 -0
- data/lib/ext/bunny-0.6.0/spec/spec_09/queue_spec.rb +205 -0
- data/lib/ext/eventmachine-0.12.10/.gitignore +14 -0
- data/lib/ext/eventmachine-0.12.10/README +82 -0
- data/lib/ext/eventmachine-0.12.10/Rakefile +374 -0
- data/lib/ext/eventmachine-0.12.10/docs/COPYING +60 -0
- data/lib/ext/eventmachine-0.12.10/docs/ChangeLog +211 -0
- data/lib/ext/eventmachine-0.12.10/docs/DEFERRABLES +133 -0
- data/lib/ext/eventmachine-0.12.10/docs/EPOLL +141 -0
- data/lib/ext/eventmachine-0.12.10/docs/GNU +281 -0
- data/lib/ext/eventmachine-0.12.10/docs/INSTALL +13 -0
- data/lib/ext/eventmachine-0.12.10/docs/KEYBOARD +38 -0
- data/lib/ext/eventmachine-0.12.10/docs/LEGAL +25 -0
- data/lib/ext/eventmachine-0.12.10/docs/LIGHTWEIGHT_CONCURRENCY +70 -0
- data/lib/ext/eventmachine-0.12.10/docs/PURE_RUBY +75 -0
- data/lib/ext/eventmachine-0.12.10/docs/RELEASE_NOTES +94 -0
- data/lib/ext/eventmachine-0.12.10/docs/SMTP +2 -0
- data/lib/ext/eventmachine-0.12.10/docs/SPAWNED_PROCESSES +89 -0
- data/lib/ext/eventmachine-0.12.10/docs/TODO +8 -0
- data/lib/ext/eventmachine-0.12.10/eventmachine.gemspec +40 -0
- data/lib/ext/eventmachine-0.12.10/examples/ex_channel.rb +43 -0
- data/lib/ext/eventmachine-0.12.10/examples/ex_queue.rb +2 -0
- data/lib/ext/eventmachine-0.12.10/examples/helper.rb +2 -0
- data/lib/ext/eventmachine-0.12.10/ext/binder.cpp +125 -0
- data/lib/ext/eventmachine-0.12.10/ext/binder.h +46 -0
- data/lib/ext/eventmachine-0.12.10/ext/cmain.cpp +827 -0
- data/lib/ext/eventmachine-0.12.10/ext/cplusplus.cpp +202 -0
- data/lib/ext/eventmachine-0.12.10/ext/ed.cpp +1893 -0
- data/lib/ext/eventmachine-0.12.10/ext/ed.h +424 -0
- data/lib/ext/eventmachine-0.12.10/ext/em.cpp +2282 -0
- data/lib/ext/eventmachine-0.12.10/ext/em.h +232 -0
- data/lib/ext/eventmachine-0.12.10/ext/emwin.cpp +300 -0
- data/lib/ext/eventmachine-0.12.10/ext/emwin.h +94 -0
- data/lib/ext/eventmachine-0.12.10/ext/epoll.cpp +26 -0
- data/lib/ext/eventmachine-0.12.10/ext/epoll.h +25 -0
- data/lib/ext/eventmachine-0.12.10/ext/eventmachine.h +122 -0
- data/lib/ext/eventmachine-0.12.10/ext/eventmachine_cpp.h +96 -0
- data/lib/ext/eventmachine-0.12.10/ext/extconf.rb +148 -0
- data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/extconf.rb +83 -0
- data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/mapper.cpp +214 -0
- data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/mapper.h +59 -0
- data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/rubymain.cpp +127 -0
- data/lib/ext/eventmachine-0.12.10/ext/files.cpp +94 -0
- data/lib/ext/eventmachine-0.12.10/ext/files.h +65 -0
- data/lib/ext/eventmachine-0.12.10/ext/kb.cpp +81 -0
- data/lib/ext/eventmachine-0.12.10/ext/page.cpp +107 -0
- data/lib/ext/eventmachine-0.12.10/ext/page.h +51 -0
- data/lib/ext/eventmachine-0.12.10/ext/pipe.cpp +349 -0
- data/lib/ext/eventmachine-0.12.10/ext/project.h +151 -0
- data/lib/ext/eventmachine-0.12.10/ext/rubymain.cpp +1166 -0
- data/lib/ext/eventmachine-0.12.10/ext/sigs.cpp +89 -0
- data/lib/ext/eventmachine-0.12.10/ext/sigs.h +32 -0
- data/lib/ext/eventmachine-0.12.10/ext/ssl.cpp +460 -0
- data/lib/ext/eventmachine-0.12.10/ext/ssl.h +94 -0
- data/lib/ext/eventmachine-0.12.10/java/.classpath +8 -0
- data/lib/ext/eventmachine-0.12.10/java/.project +17 -0
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EmReactor.java +570 -0
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableChannel.java +69 -0
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableDatagramChannel.java +189 -0
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableSocketChannel.java +364 -0
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Application.java +194 -0
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Connection.java +74 -0
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/ConnectionFactory.java +37 -0
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +46 -0
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/PeriodicTimer.java +38 -0
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Timer.java +54 -0
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/ApplicationTest.java +109 -0
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/ConnectTest.java +148 -0
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/EMTest.java +80 -0
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -0
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestServers.java +75 -0
- data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestTimers.java +90 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/buftok.rb +138 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/callback.rb +26 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/channel.rb +57 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/connection.rb +564 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/deferrable.rb +192 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/file_watch.rb +54 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/future.rb +61 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/messages.rb +66 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/process_watch.rb +44 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/processes.rb +119 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/header_and_content.rb +138 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/httpclient.rb +263 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/httpclient2.rb +590 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/line_and_text.rb +125 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/linetext2.rb +161 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/memcache.rb +323 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/object_protocol.rb +45 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/postgres3.rb +247 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/saslauth.rb +175 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/smtpclient.rb +357 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/smtpserver.rb +547 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/socks4.rb +66 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/stomp.rb +200 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols/tcptest.rb +53 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/protocols.rb +36 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/queue.rb +61 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/spawnable.rb +85 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/streamer.rb +130 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/timers.rb +56 -0
- data/lib/ext/eventmachine-0.12.10/lib/em/version.rb +3 -0
- data/lib/ext/eventmachine-0.12.10/lib/eventmachine.rb +1592 -0
- data/lib/ext/eventmachine-0.12.10/lib/evma/callback.rb +32 -0
- data/lib/ext/eventmachine-0.12.10/lib/evma/container.rb +75 -0
- data/lib/ext/eventmachine-0.12.10/lib/evma/factory.rb +77 -0
- data/lib/ext/eventmachine-0.12.10/lib/evma/protocol.rb +87 -0
- data/lib/ext/eventmachine-0.12.10/lib/evma/reactor.rb +48 -0
- data/lib/ext/eventmachine-0.12.10/lib/evma.rb +32 -0
- data/lib/ext/eventmachine-0.12.10/lib/jeventmachine.rb +257 -0
- data/lib/ext/eventmachine-0.12.10/lib/pr_eventmachine.rb +1022 -0
- data/lib/ext/eventmachine-0.12.10/setup.rb +1585 -0
- data/lib/ext/eventmachine-0.12.10/tasks/cpp.rake_example +77 -0
- data/lib/ext/eventmachine-0.12.10/tests/client.crt +31 -0
- data/lib/ext/eventmachine-0.12.10/tests/client.key +51 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_attach.rb +126 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_basic.rb +284 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_channel.rb +63 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_connection_count.rb +35 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_defer.rb +47 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_epoll.rb +160 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_error_handler.rb +35 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_errors.rb +82 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_exc.rb +55 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_file_watch.rb +49 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_futures.rb +198 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_get_sock_opt.rb +30 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_handler_check.rb +37 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_hc.rb +218 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_httpclient.rb +218 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_httpclient2.rb +153 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_inactivity_timeout.rb +50 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_kb.rb +60 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_ltp.rb +182 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_ltp2.rb +317 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_next_tick.rb +133 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_object_protocol.rb +37 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_pause.rb +70 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_pending_connect_timeout.rb +48 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_process_watch.rb +48 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_processes.rb +128 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_proxy_connection.rb +92 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_pure.rb +125 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_queue.rb +44 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_running.rb +42 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_sasl.rb +72 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_send_file.rb +242 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_servers.rb +76 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_smtpclient.rb +83 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_smtpserver.rb +85 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_spawn.rb +322 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_ssl_args.rb +79 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_ssl_methods.rb +50 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_ssl_verify.rb +82 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_timers.rb +162 -0
- data/lib/ext/eventmachine-0.12.10/tests/test_ud.rb +36 -0
- data/lib/ext/eventmachine-0.12.10/tests/testem.rb +31 -0
- data/lib/ext/eventmachine-0.12.10/web/whatis +7 -0
- data/lib/ext/misc/README +1 -0
- data/lib/ext/misc/indifferent_access.rb +131 -0
- data/lib/ext/uuidtools-2.1.1/CHANGELOG +56 -0
- data/lib/ext/uuidtools-2.1.1/LICENSE +20 -0
- data/lib/ext/uuidtools-2.1.1/README +13 -0
- data/lib/ext/uuidtools-2.1.1/Rakefile +48 -0
- data/lib/ext/uuidtools-2.1.1/lib/compat/securerandom.rb +202 -0
- data/lib/ext/uuidtools-2.1.1/lib/uuidtools/version.rb +35 -0
- data/lib/ext/uuidtools-2.1.1/lib/uuidtools.rb +618 -0
- data/lib/ext/uuidtools-2.1.1/spec/spec.opts +1 -0
- data/lib/ext/uuidtools-2.1.1/spec/spec_helper.rb +7 -0
- data/lib/ext/uuidtools-2.1.1/spec/uuidtools/mac_address_spec.rb +15 -0
- data/lib/ext/uuidtools-2.1.1/spec/uuidtools/utility_spec.rb +21 -0
- data/lib/ext/uuidtools-2.1.1/spec/uuidtools/uuid_creation_spec.rb +121 -0
- data/lib/ext/uuidtools-2.1.1/spec/uuidtools/uuid_parsing_spec.rb +127 -0
- data/lib/ext/uuidtools-2.1.1/tasks/benchmark.rake +38 -0
- data/lib/ext/uuidtools-2.1.1/tasks/clobber.rake +2 -0
- data/lib/ext/uuidtools-2.1.1/tasks/gem.rake +68 -0
- data/lib/ext/uuidtools-2.1.1/tasks/git.rake +40 -0
- data/lib/ext/uuidtools-2.1.1/tasks/metrics.rake +22 -0
- data/lib/ext/uuidtools-2.1.1/tasks/rdoc.rake +29 -0
- data/lib/ext/uuidtools-2.1.1/tasks/rubyforge.rake +89 -0
- data/lib/ext/uuidtools-2.1.1/tasks/spec.rake +64 -0
- data/lib/ext/uuidtools-2.1.1/website/index.html +95 -0
- data/lib/sidekick/client/sidekick_client.rb +46 -0
- data/lib/sidekick/shared/sidekick_logger.rb +14 -0
- data/lib/sidekick/shared/sidekick_queue_publisher.rb +91 -0
- data/lib/sidekick-client.rb +7 -0
- data/sidekick-client.gemspec +289 -0
- data/test/helper.rb +10 -0
- data/test/test_sidekick-client.rb +7 -0
- metadata +311 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
#--
|
2
|
+
# UUIDTools, Copyright (c) 2005-2008 Bob Aman
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
# Used to prevent the class/module from being loaded more than once
|
25
|
+
unless defined? UUID::VERSION
|
26
|
+
class UUID
|
27
|
+
module VERSION #:nodoc:
|
28
|
+
MAJOR = 2
|
29
|
+
MINOR = 1
|
30
|
+
TINY = 1
|
31
|
+
|
32
|
+
STRING = [MAJOR, MINOR, TINY].join('.')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,618 @@
|
|
1
|
+
#--
|
2
|
+
# UUIDTools, Copyright (c) 2005-2008 Bob Aman
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
$:.unshift(File.dirname(__FILE__))
|
25
|
+
|
26
|
+
require 'uri'
|
27
|
+
require 'time'
|
28
|
+
require 'thread'
|
29
|
+
require 'digest/sha1'
|
30
|
+
require 'digest/md5'
|
31
|
+
|
32
|
+
require 'uuidtools/version'
|
33
|
+
|
34
|
+
begin
|
35
|
+
require 'securerandom'
|
36
|
+
rescue LoadError
|
37
|
+
require File.join(File.dirname(__FILE__), 'compat', 'securerandom')
|
38
|
+
end
|
39
|
+
|
40
|
+
module UUIDTools
|
41
|
+
#= uuidtools.rb
|
42
|
+
#
|
43
|
+
# UUIDTools was designed to be a simple library for generating any
|
44
|
+
# of the various types of UUIDs. It conforms to RFC 4122 whenever
|
45
|
+
# possible.
|
46
|
+
#
|
47
|
+
#== Example
|
48
|
+
# UUID.md5_create(UUID_DNS_NAMESPACE, "www.widgets.com")
|
49
|
+
# => #<UUID:0x287576 UUID:3d813cbb-47fb-32ba-91df-831e1593ac29>
|
50
|
+
# UUID.sha1_create(UUID_DNS_NAMESPACE, "www.widgets.com")
|
51
|
+
# => #<UUID:0x2a0116 UUID:21f7f8de-8051-5b89-8680-0195ef798b6a>
|
52
|
+
# UUID.timestamp_create
|
53
|
+
# => #<UUID:0x2adfdc UUID:64a5189c-25b3-11da-a97b-00c04fd430c8>
|
54
|
+
# UUID.random_create
|
55
|
+
# => #<UUID:0x19013a UUID:984265dc-4200-4f02-ae70-fe4f48964159>
|
56
|
+
class UUID
|
57
|
+
include Comparable
|
58
|
+
|
59
|
+
@@last_timestamp = nil
|
60
|
+
@@last_node_id = nil
|
61
|
+
@@last_clock_sequence = nil
|
62
|
+
@@state_file = nil
|
63
|
+
@@mutex = Mutex.new
|
64
|
+
|
65
|
+
def initialize(time_low, time_mid, time_hi_and_version,
|
66
|
+
clock_seq_hi_and_reserved, clock_seq_low, nodes)
|
67
|
+
unless time_low >= 0 && time_low < 4294967296
|
68
|
+
raise ArgumentError,
|
69
|
+
"Expected unsigned 32-bit number for time_low, got #{time_low}."
|
70
|
+
end
|
71
|
+
unless time_mid >= 0 && time_mid < 65536
|
72
|
+
raise ArgumentError,
|
73
|
+
"Expected unsigned 16-bit number for time_mid, got #{time_mid}."
|
74
|
+
end
|
75
|
+
unless time_hi_and_version >= 0 && time_hi_and_version < 65536
|
76
|
+
raise ArgumentError,
|
77
|
+
"Expected unsigned 16-bit number for time_hi_and_version, " +
|
78
|
+
"got #{time_hi_and_version}."
|
79
|
+
end
|
80
|
+
unless clock_seq_hi_and_reserved >= 0 && clock_seq_hi_and_reserved < 256
|
81
|
+
raise ArgumentError,
|
82
|
+
"Expected unsigned 8-bit number for clock_seq_hi_and_reserved, " +
|
83
|
+
"got #{clock_seq_hi_and_reserved}."
|
84
|
+
end
|
85
|
+
unless clock_seq_low >= 0 && clock_seq_low < 256
|
86
|
+
raise ArgumentError,
|
87
|
+
"Expected unsigned 8-bit number for clock_seq_low, " +
|
88
|
+
"got #{clock_seq_low}."
|
89
|
+
end
|
90
|
+
unless nodes.kind_of?(Enumerable)
|
91
|
+
raise TypeError,
|
92
|
+
"Expected Enumerable, got #{nodes.class.name}."
|
93
|
+
end
|
94
|
+
unless nodes.size == 6
|
95
|
+
raise ArgumentError,
|
96
|
+
"Expected nodes to have size of 6."
|
97
|
+
end
|
98
|
+
for node in nodes
|
99
|
+
unless node >= 0 && node < 256
|
100
|
+
raise ArgumentError,
|
101
|
+
"Expected unsigned 8-bit number for each node, " +
|
102
|
+
"got #{node}."
|
103
|
+
end
|
104
|
+
end
|
105
|
+
@time_low = time_low
|
106
|
+
@time_mid = time_mid
|
107
|
+
@time_hi_and_version = time_hi_and_version
|
108
|
+
@clock_seq_hi_and_reserved = clock_seq_hi_and_reserved
|
109
|
+
@clock_seq_low = clock_seq_low
|
110
|
+
@nodes = nodes
|
111
|
+
end
|
112
|
+
|
113
|
+
attr_accessor :time_low
|
114
|
+
attr_accessor :time_mid
|
115
|
+
attr_accessor :time_hi_and_version
|
116
|
+
attr_accessor :clock_seq_hi_and_reserved
|
117
|
+
attr_accessor :clock_seq_low
|
118
|
+
attr_accessor :nodes
|
119
|
+
|
120
|
+
# Parses a UUID from a string.
|
121
|
+
def self.parse(uuid_string)
|
122
|
+
unless uuid_string.kind_of? String
|
123
|
+
raise TypeError,
|
124
|
+
"Expected String, got #{uuid_string.class.name} instead."
|
125
|
+
end
|
126
|
+
uuid_components = uuid_string.downcase.scan(
|
127
|
+
Regexp.new("^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-" +
|
128
|
+
"([0-9a-f]{2})([0-9a-f]{2})-([0-9a-f]{12})$")).first
|
129
|
+
raise ArgumentError, "Invalid UUID format." if uuid_components.nil?
|
130
|
+
time_low = uuid_components[0].to_i(16)
|
131
|
+
time_mid = uuid_components[1].to_i(16)
|
132
|
+
time_hi_and_version = uuid_components[2].to_i(16)
|
133
|
+
clock_seq_hi_and_reserved = uuid_components[3].to_i(16)
|
134
|
+
clock_seq_low = uuid_components[4].to_i(16)
|
135
|
+
nodes = []
|
136
|
+
for i in 0..5
|
137
|
+
nodes << uuid_components[5][(i * 2)..(i * 2) + 1].to_i(16)
|
138
|
+
end
|
139
|
+
return self.new(time_low, time_mid, time_hi_and_version,
|
140
|
+
clock_seq_hi_and_reserved, clock_seq_low, nodes)
|
141
|
+
end
|
142
|
+
|
143
|
+
# Parses a UUID from a raw byte string.
|
144
|
+
def self.parse_raw(raw_string)
|
145
|
+
unless raw_string.kind_of? String
|
146
|
+
raise TypeError,
|
147
|
+
"Expected String, got #{raw_string.class.name} instead."
|
148
|
+
end
|
149
|
+
integer = self.convert_byte_string_to_int(raw_string)
|
150
|
+
|
151
|
+
time_low = (integer >> 96) & 0xFFFFFFFF
|
152
|
+
time_mid = (integer >> 80) & 0xFFFF
|
153
|
+
time_hi_and_version = (integer >> 64) & 0xFFFF
|
154
|
+
clock_seq_hi_and_reserved = (integer >> 56) & 0xFF
|
155
|
+
clock_seq_low = (integer >> 48) & 0xFF
|
156
|
+
nodes = []
|
157
|
+
for i in 0..5
|
158
|
+
nodes << ((integer >> (40 - (i * 8))) & 0xFF)
|
159
|
+
end
|
160
|
+
return self.new(time_low, time_mid, time_hi_and_version,
|
161
|
+
clock_seq_hi_and_reserved, clock_seq_low, nodes)
|
162
|
+
end
|
163
|
+
|
164
|
+
# Parses a UUID from an Integer.
|
165
|
+
def self.parse_int(uuid_int)
|
166
|
+
unless uuid_int.kind_of?(Integer)
|
167
|
+
raise ArgumentError,
|
168
|
+
"Expected Integer, got #{uuid_int.class.name} instead."
|
169
|
+
end
|
170
|
+
return self.parse_raw(self.convert_int_to_byte_string(uuid_int, 16))
|
171
|
+
end
|
172
|
+
|
173
|
+
# Parse a UUID from a hexdigest String.
|
174
|
+
def self.parse_hexdigest(uuid_hexdigest)
|
175
|
+
unless uuid_hexdigest.kind_of?(String)
|
176
|
+
raise ArgumentError,
|
177
|
+
"Expected String, got #{uuid_hexdigest.class.name} instead."
|
178
|
+
end
|
179
|
+
return self.parse_int(uuid_hexdigest.to_i(16))
|
180
|
+
end
|
181
|
+
|
182
|
+
# Creates a UUID from a random value.
|
183
|
+
def self.random_create()
|
184
|
+
new_uuid = self.parse_raw(SecureRandom.random_bytes(16))
|
185
|
+
new_uuid.time_hi_and_version &= 0x0FFF
|
186
|
+
new_uuid.time_hi_and_version |= (4 << 12)
|
187
|
+
new_uuid.clock_seq_hi_and_reserved &= 0x3F
|
188
|
+
new_uuid.clock_seq_hi_and_reserved |= 0x80
|
189
|
+
return new_uuid
|
190
|
+
end
|
191
|
+
|
192
|
+
# Creates a UUID from a timestamp.
|
193
|
+
def self.timestamp_create(timestamp=nil)
|
194
|
+
# We need a lock here to prevent two threads from ever
|
195
|
+
# getting the same timestamp.
|
196
|
+
@@mutex.synchronize do
|
197
|
+
# Always use GMT to generate UUIDs.
|
198
|
+
if timestamp.nil?
|
199
|
+
gmt_timestamp = Time.now.gmtime
|
200
|
+
else
|
201
|
+
gmt_timestamp = timestamp.gmtime
|
202
|
+
end
|
203
|
+
# Convert to 100 nanosecond blocks
|
204
|
+
gmt_timestamp_100_nanoseconds = (gmt_timestamp.tv_sec * 10000000) +
|
205
|
+
(gmt_timestamp.tv_usec * 10) + 0x01B21DD213814000
|
206
|
+
mac_address = self.mac_address
|
207
|
+
node_id = 0
|
208
|
+
if mac_address != nil
|
209
|
+
nodes = mac_address.split(":").collect do |octet|
|
210
|
+
octet.to_i(16)
|
211
|
+
end
|
212
|
+
else
|
213
|
+
nodes = SecureRandom.random_bytes(6).unpack("C*")
|
214
|
+
nodes[0] |= 0b00000001
|
215
|
+
end
|
216
|
+
for i in 0..5
|
217
|
+
node_id += (nodes[i] << (40 - (i * 8)))
|
218
|
+
end
|
219
|
+
clock_sequence = @@last_clock_sequence
|
220
|
+
if clock_sequence.nil?
|
221
|
+
clock_sequence = self.convert_byte_string_to_int(
|
222
|
+
SecureRandom.random_bytes(16)
|
223
|
+
)
|
224
|
+
end
|
225
|
+
if @@last_node_id != nil && @@last_node_id != node_id
|
226
|
+
# The node id has changed. Change the clock id.
|
227
|
+
clock_sequence = self.convert_byte_string_to_int(
|
228
|
+
SecureRandom.random_bytes(16)
|
229
|
+
)
|
230
|
+
elsif @@last_timestamp != nil &&
|
231
|
+
gmt_timestamp_100_nanoseconds <= @@last_timestamp
|
232
|
+
clock_sequence = clock_sequence + 1
|
233
|
+
end
|
234
|
+
@@last_timestamp = gmt_timestamp_100_nanoseconds
|
235
|
+
@@last_node_id = node_id
|
236
|
+
@@last_clock_sequence = clock_sequence
|
237
|
+
|
238
|
+
time_low = gmt_timestamp_100_nanoseconds & 0xFFFFFFFF
|
239
|
+
time_mid = ((gmt_timestamp_100_nanoseconds >> 32) & 0xFFFF)
|
240
|
+
time_hi_and_version = ((gmt_timestamp_100_nanoseconds >> 48) & 0x0FFF)
|
241
|
+
time_hi_and_version |= (1 << 12)
|
242
|
+
clock_seq_low = clock_sequence & 0xFF;
|
243
|
+
clock_seq_hi_and_reserved = (clock_sequence & 0x3F00) >> 8
|
244
|
+
clock_seq_hi_and_reserved |= 0x80
|
245
|
+
|
246
|
+
return self.new(time_low, time_mid, time_hi_and_version,
|
247
|
+
clock_seq_hi_and_reserved, clock_seq_low, nodes)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
# Creates a UUID using the MD5 hash. (Version 3)
|
252
|
+
def self.md5_create(namespace, name)
|
253
|
+
return self.create_from_hash(Digest::MD5, namespace, name)
|
254
|
+
end
|
255
|
+
|
256
|
+
# Creates a UUID using the SHA1 hash. (Version 5)
|
257
|
+
def self.sha1_create(namespace, name)
|
258
|
+
return self.create_from_hash(Digest::SHA1, namespace, name)
|
259
|
+
end
|
260
|
+
|
261
|
+
# This method applies only to version 1 UUIDs.
|
262
|
+
# Checks if the node ID was generated from a random number
|
263
|
+
# or from an IEEE 802 address (MAC address).
|
264
|
+
# Always returns false for UUIDs that aren't version 1.
|
265
|
+
# This should not be confused with version 4 UUIDs where
|
266
|
+
# more than just the node id is random.
|
267
|
+
def random_node_id?
|
268
|
+
return false if self.version != 1
|
269
|
+
return ((self.nodes.first & 0x01) == 1)
|
270
|
+
end
|
271
|
+
|
272
|
+
# Returns true if this UUID is the
|
273
|
+
# nil UUID (00000000-0000-0000-0000-000000000000).
|
274
|
+
def nil_uuid?
|
275
|
+
return false if self.time_low != 0
|
276
|
+
return false if self.time_mid != 0
|
277
|
+
return false if self.time_hi_and_version != 0
|
278
|
+
return false if self.clock_seq_hi_and_reserved != 0
|
279
|
+
return false if self.clock_seq_low != 0
|
280
|
+
self.nodes.each do |node|
|
281
|
+
return false if node != 0
|
282
|
+
end
|
283
|
+
return true
|
284
|
+
end
|
285
|
+
|
286
|
+
# Returns the UUID version type.
|
287
|
+
# Possible values:
|
288
|
+
# 1 - Time-based with unique or random host identifier
|
289
|
+
# 2 - DCE Security version (with POSIX UIDs)
|
290
|
+
# 3 - Name-based (MD5 hash)
|
291
|
+
# 4 - Random
|
292
|
+
# 5 - Name-based (SHA-1 hash)
|
293
|
+
def version
|
294
|
+
return (time_hi_and_version >> 12)
|
295
|
+
end
|
296
|
+
|
297
|
+
# Returns the UUID variant.
|
298
|
+
# Possible values:
|
299
|
+
# 0b000 - Reserved, NCS backward compatibility.
|
300
|
+
# 0b100 - The variant specified in this document.
|
301
|
+
# 0b110 - Reserved, Microsoft Corporation backward compatibility.
|
302
|
+
# 0b111 - Reserved for future definition.
|
303
|
+
def variant
|
304
|
+
variant_raw = (clock_seq_hi_and_reserved >> 5)
|
305
|
+
result = nil
|
306
|
+
if (variant_raw >> 2) == 0
|
307
|
+
result = 0x000
|
308
|
+
elsif (variant_raw >> 1) == 2
|
309
|
+
result = 0x100
|
310
|
+
else
|
311
|
+
result = variant_raw
|
312
|
+
end
|
313
|
+
return (result >> 6)
|
314
|
+
end
|
315
|
+
|
316
|
+
# Returns true if this UUID is valid.
|
317
|
+
def valid?
|
318
|
+
if [0b000, 0b100, 0b110, 0b111].include?(self.variant) &&
|
319
|
+
(1..5).include?(self.version)
|
320
|
+
return true
|
321
|
+
else
|
322
|
+
return false
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
# Returns the IEEE 802 address used to generate this UUID or
|
327
|
+
# nil if a MAC address was not used.
|
328
|
+
def mac_address
|
329
|
+
return nil if self.version != 1
|
330
|
+
return nil if self.random_node_id?
|
331
|
+
return (self.nodes.collect do |node|
|
332
|
+
sprintf("%2.2x", node)
|
333
|
+
end).join(":")
|
334
|
+
end
|
335
|
+
|
336
|
+
# Returns the timestamp used to generate this UUID
|
337
|
+
def timestamp
|
338
|
+
return nil if self.version != 1
|
339
|
+
gmt_timestamp_100_nanoseconds = 0
|
340
|
+
gmt_timestamp_100_nanoseconds +=
|
341
|
+
((self.time_hi_and_version & 0x0FFF) << 48)
|
342
|
+
gmt_timestamp_100_nanoseconds += (self.time_mid << 32)
|
343
|
+
gmt_timestamp_100_nanoseconds += self.time_low
|
344
|
+
return Time.at(
|
345
|
+
(gmt_timestamp_100_nanoseconds - 0x01B21DD213814000) / 10000000.0)
|
346
|
+
end
|
347
|
+
|
348
|
+
# Compares two UUIDs lexically
|
349
|
+
def <=>(other_uuid)
|
350
|
+
check = self.time_low <=> other_uuid.time_low
|
351
|
+
return check if check != 0
|
352
|
+
check = self.time_mid <=> other_uuid.time_mid
|
353
|
+
return check if check != 0
|
354
|
+
check = self.time_hi_and_version <=> other_uuid.time_hi_and_version
|
355
|
+
return check if check != 0
|
356
|
+
check = self.clock_seq_hi_and_reserved <=>
|
357
|
+
other_uuid.clock_seq_hi_and_reserved
|
358
|
+
return check if check != 0
|
359
|
+
check = self.clock_seq_low <=> other_uuid.clock_seq_low
|
360
|
+
return check if check != 0
|
361
|
+
for i in 0..5
|
362
|
+
if (self.nodes[i] < other_uuid.nodes[i])
|
363
|
+
return -1
|
364
|
+
end
|
365
|
+
if (self.nodes[i] > other_uuid.nodes[i])
|
366
|
+
return 1
|
367
|
+
end
|
368
|
+
end
|
369
|
+
return 0
|
370
|
+
end
|
371
|
+
|
372
|
+
# Returns a representation of the object's state
|
373
|
+
def inspect
|
374
|
+
return "#<UUID:0x#{self.object_id.to_s(16)} UUID:#{self.to_s}>"
|
375
|
+
end
|
376
|
+
|
377
|
+
# Returns the hex digest of the UUID object.
|
378
|
+
def hexdigest
|
379
|
+
return self.to_i.to_s(16).rjust(32, "0")
|
380
|
+
end
|
381
|
+
|
382
|
+
# Returns the raw bytes that represent this UUID.
|
383
|
+
def raw
|
384
|
+
return self.class.convert_int_to_byte_string(self.to_i, 16)
|
385
|
+
end
|
386
|
+
|
387
|
+
# Returns a string representation for this UUID.
|
388
|
+
def to_s
|
389
|
+
result = sprintf("%8.8x-%4.4x-%4.4x-%2.2x%2.2x-", @time_low, @time_mid,
|
390
|
+
@time_hi_and_version, @clock_seq_hi_and_reserved, @clock_seq_low);
|
391
|
+
for i in 0..5
|
392
|
+
result << sprintf("%2.2x", @nodes[i])
|
393
|
+
end
|
394
|
+
return result.downcase
|
395
|
+
end
|
396
|
+
alias_method :to_str, :to_s
|
397
|
+
|
398
|
+
# Returns an integer representation for this UUID.
|
399
|
+
def to_i
|
400
|
+
@integer ||= (begin
|
401
|
+
bytes = (time_low << 96) + (time_mid << 80) +
|
402
|
+
(time_hi_and_version << 64) + (clock_seq_hi_and_reserved << 56) +
|
403
|
+
(clock_seq_low << 48)
|
404
|
+
for i in 0..5
|
405
|
+
bytes += (nodes[i] << (40 - (i * 8)))
|
406
|
+
end
|
407
|
+
bytes
|
408
|
+
end)
|
409
|
+
end
|
410
|
+
|
411
|
+
# Returns a URI string for this UUID.
|
412
|
+
def to_uri
|
413
|
+
return "urn:uuid:#{self.to_s}"
|
414
|
+
end
|
415
|
+
|
416
|
+
# Returns an integer hash value.
|
417
|
+
def hash
|
418
|
+
@hash ||= self.to_i % 0x3fffffff
|
419
|
+
end
|
420
|
+
|
421
|
+
# Returns true if this UUID is exactly equal to the other UUID.
|
422
|
+
def eql?(other)
|
423
|
+
return self == other
|
424
|
+
end
|
425
|
+
|
426
|
+
# Returns the MAC address of the current computer's network card.
|
427
|
+
# Returns nil if a MAC address could not be found.
|
428
|
+
def self.mac_address #:nodoc:
|
429
|
+
if !defined?(@@mac_address)
|
430
|
+
require 'rbconfig'
|
431
|
+
os_platform = Config::CONFIG['target_os']
|
432
|
+
os_class = nil
|
433
|
+
if (os_platform =~ /win/i && !(os_platform =~ /darwin/i)) ||
|
434
|
+
os_platform =~ /w32/i
|
435
|
+
os_class = :windows
|
436
|
+
elsif os_platform =~ /solaris/i
|
437
|
+
os_class = :solaris
|
438
|
+
elsif os_platform =~ /netbsd/i
|
439
|
+
os_class = :netbsd
|
440
|
+
elsif os_platform =~ /openbsd/i
|
441
|
+
os_class = :openbsd
|
442
|
+
end
|
443
|
+
mac_regexps = [
|
444
|
+
Regexp.new("address:? (#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"),
|
445
|
+
Regexp.new("addr:? (#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"),
|
446
|
+
Regexp.new("ether:? (#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"),
|
447
|
+
Regexp.new("(#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"),
|
448
|
+
Regexp.new("(#{(["[0-9a-fA-F]{2}"] * 6).join("-")})")
|
449
|
+
]
|
450
|
+
parse_mac = lambda do |output|
|
451
|
+
(mac_regexps.map do |regexp|
|
452
|
+
result = output[regexp, 1]
|
453
|
+
result.downcase.gsub(/-/, ":") if result != nil
|
454
|
+
end).compact.first
|
455
|
+
end
|
456
|
+
if os_class == :windows
|
457
|
+
script_in_path = true
|
458
|
+
else
|
459
|
+
script_in_path = Kernel.system("which ifconfig 2>&1 > /dev/null")
|
460
|
+
end
|
461
|
+
if os_class == :solaris
|
462
|
+
begin
|
463
|
+
ifconfig_output =
|
464
|
+
(script_in_path ? `ifconfig -a` : `/sbin/ifconfig -a`)
|
465
|
+
ip_addresses = ifconfig_output.scan(
|
466
|
+
/inet\s?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/)
|
467
|
+
ip = ip_addresses.find {|addr| addr[0] != '127.0.0.1'}[0]
|
468
|
+
@@mac_address = `/usr/sbin/arp #{ip}`.split(' ')[3]
|
469
|
+
rescue Exception
|
470
|
+
end
|
471
|
+
if @@mac_address == "" || @@mac_address == nil
|
472
|
+
begin
|
473
|
+
ifconfig_output =
|
474
|
+
(script_in_path ?
|
475
|
+
`ifconfig -a` : `/sbin/ifconfig -a`).split(' ')
|
476
|
+
index = ifconfig_output.index("inet") + 1
|
477
|
+
ip = ifconfig_output[index]
|
478
|
+
@@mac_address = `arp #{ip}`.split(' ')[3]
|
479
|
+
rescue Exception
|
480
|
+
end
|
481
|
+
end
|
482
|
+
elsif os_class == :windows
|
483
|
+
begin
|
484
|
+
@@mac_address = parse_mac.call(`ipconfig /all`)
|
485
|
+
rescue
|
486
|
+
end
|
487
|
+
else
|
488
|
+
begin
|
489
|
+
if os_class == :netbsd
|
490
|
+
@@mac_address = parse_mac.call(
|
491
|
+
script_in_path ? `ifconfig -a 2>&1` : `/sbin/ifconfig -a 2>&1`
|
492
|
+
)
|
493
|
+
elsif os_class == :openbsd
|
494
|
+
@@mac_address = parse_mac.call(
|
495
|
+
script_in_path ? `ifconfig -a 2>&1` : `/sbin/ifconfig -a 2>&1`
|
496
|
+
)
|
497
|
+
elsif File.exists?('/sbin/ifconfig')
|
498
|
+
@@mac_address = parse_mac.call(
|
499
|
+
script_in_path ? `ifconfig 2>&1` : `/sbin/ifconfig 2>&1`
|
500
|
+
)
|
501
|
+
if @@mac_address == nil
|
502
|
+
@@mac_address = parse_mac.call(
|
503
|
+
script_in_path ?
|
504
|
+
`ifconfig -a 2>&1` : `/sbin/ifconfig -a 2>&1`
|
505
|
+
)
|
506
|
+
end
|
507
|
+
if @@mac_address == nil
|
508
|
+
@@mac_address = parse_mac.call(
|
509
|
+
script_in_path ?
|
510
|
+
`ifconfig | grep HWaddr | cut -c39- 2>&1` :
|
511
|
+
`/sbin/ifconfig | grep HWaddr | cut -c39- 2>&1`
|
512
|
+
)
|
513
|
+
end
|
514
|
+
else
|
515
|
+
@@mac_address = parse_mac.call(
|
516
|
+
script_in_path ? `ifconfig 2>&1` : `/sbin/ifconfig 2>&1`
|
517
|
+
)
|
518
|
+
if @@mac_address == nil
|
519
|
+
@@mac_address = parse_mac.call(
|
520
|
+
script_in_path ?
|
521
|
+
`ifconfig -a 2>&1` : `/sbin/ifconfig -a 2>&1`
|
522
|
+
)
|
523
|
+
end
|
524
|
+
if @@mac_address == nil
|
525
|
+
@@mac_address = parse_mac.call(
|
526
|
+
script_in_path ?
|
527
|
+
`ifconfig | grep HWaddr | cut -c39- 2>&1` :
|
528
|
+
`/sbin/ifconfig | grep HWaddr | cut -c39- 2>&1`
|
529
|
+
)
|
530
|
+
end
|
531
|
+
end
|
532
|
+
rescue
|
533
|
+
end
|
534
|
+
end
|
535
|
+
if @@mac_address != nil
|
536
|
+
if @@mac_address.respond_to?(:to_str)
|
537
|
+
@@mac_address = @@mac_address.to_str
|
538
|
+
else
|
539
|
+
@@mac_address = @@mac_address.to_s
|
540
|
+
end
|
541
|
+
@@mac_address.downcase!
|
542
|
+
@@mac_address.strip!
|
543
|
+
end
|
544
|
+
|
545
|
+
# Verify that the MAC address is in the right format.
|
546
|
+
# Nil it out if it isn't.
|
547
|
+
unless @@mac_address.respond_to?(:scan) &&
|
548
|
+
@@mac_address.scan(/#{(["[0-9a-f]{2}"] * 6).join(":")}/)
|
549
|
+
@@mac_address = nil
|
550
|
+
end
|
551
|
+
end
|
552
|
+
return @@mac_address
|
553
|
+
end
|
554
|
+
|
555
|
+
# Allows users to set the MAC address manually in cases where the MAC
|
556
|
+
# address cannot be obtained programatically.
|
557
|
+
def self.mac_address=(new_mac_address)
|
558
|
+
@@mac_address = new_mac_address
|
559
|
+
end
|
560
|
+
|
561
|
+
# The following methods are not part of the public API,
|
562
|
+
# and generally should not be called directly.
|
563
|
+
|
564
|
+
# Creates a new UUID from a SHA1 or MD5 hash
|
565
|
+
def self.create_from_hash(hash_class, namespace, name) #:nodoc:
|
566
|
+
if hash_class == Digest::MD5
|
567
|
+
version = 3
|
568
|
+
elsif hash_class == Digest::SHA1
|
569
|
+
version = 5
|
570
|
+
else
|
571
|
+
raise ArgumentError,
|
572
|
+
"Expected Digest::SHA1 or Digest::MD5, got #{hash_class.name}."
|
573
|
+
end
|
574
|
+
hash = hash_class.new
|
575
|
+
hash.update(namespace.raw)
|
576
|
+
hash.update(name)
|
577
|
+
hash_string = hash.to_s[0..31]
|
578
|
+
new_uuid = self.parse("#{hash_string[0..7]}-#{hash_string[8..11]}-" +
|
579
|
+
"#{hash_string[12..15]}-#{hash_string[16..19]}-#{hash_string[20..31]}")
|
580
|
+
|
581
|
+
new_uuid.time_hi_and_version &= 0x0FFF
|
582
|
+
new_uuid.time_hi_and_version |= (version << 12)
|
583
|
+
new_uuid.clock_seq_hi_and_reserved &= 0x3F
|
584
|
+
new_uuid.clock_seq_hi_and_reserved |= 0x80
|
585
|
+
return new_uuid
|
586
|
+
end
|
587
|
+
|
588
|
+
def self.convert_int_to_byte_string(integer, size) #:nodoc:
|
589
|
+
byte_string = ""
|
590
|
+
if byte_string.respond_to?(:force_encoding)
|
591
|
+
byte_string.force_encoding(Encoding::ASCII_8BIT)
|
592
|
+
end
|
593
|
+
for i in 0..(size - 1)
|
594
|
+
byte_string << ((integer >> (((size - 1) - i) * 8)) & 0xFF)
|
595
|
+
end
|
596
|
+
return byte_string
|
597
|
+
end
|
598
|
+
|
599
|
+
def self.convert_byte_string_to_int(byte_string) #:nodoc:
|
600
|
+
if byte_string.respond_to?(:force_encoding)
|
601
|
+
byte_string.force_encoding(Encoding::ASCII_8BIT)
|
602
|
+
end
|
603
|
+
integer = 0
|
604
|
+
size = byte_string.size
|
605
|
+
for i in 0..(size - 1)
|
606
|
+
ordinal = (byte_string[i].respond_to?(:ord) ?
|
607
|
+
byte_string[i].ord : byte_string[i])
|
608
|
+
integer += (ordinal << (((size - 1) - i) * 8))
|
609
|
+
end
|
610
|
+
return integer
|
611
|
+
end
|
612
|
+
end
|
613
|
+
|
614
|
+
UUID_DNS_NAMESPACE = UUID.parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
|
615
|
+
UUID_URL_NAMESPACE = UUID.parse("6ba7b811-9dad-11d1-80b4-00c04fd430c8")
|
616
|
+
UUID_OID_NAMESPACE = UUID.parse("6ba7b812-9dad-11d1-80b4-00c04fd430c8")
|
617
|
+
UUID_X500_NAMESPACE = UUID.parse("6ba7b814-9dad-11d1-80b4-00c04fd430c8")
|
618
|
+
end
|