Add "uuid" library and make sessionmanager use this.
authorMatthew Wild <mwild1@gmail.com>
Sat, 4 Oct 2008 01:12:54 +0000 (02:12 +0100)
committerMatthew Wild <mwild1@gmail.com>
Sat, 4 Oct 2008 01:12:54 +0000 (02:12 +0100)
...and yes, the uuid generation needs work :P

core/sessionmanager.lua
util/uuid.lua [new file with mode: 0644]

index f19721ed148f2045772abe23f5965ffe9fe9f5be..f2542ed2783c27178fc55eb6ca69e9a308c5a599 100644 (file)
@@ -12,7 +12,7 @@ local hosts = hosts;
 local modulemanager = require "core.modulemanager";
 local log = require "util.logger".init("sessionmanager");
 local error = error;
-
+local uuid_generate = require "util.uuid".uuid_generate;
 module "sessionmanager"
 
 function new_session(conn)
@@ -41,7 +41,7 @@ end
 function bind_resource(session, resource)
        if not session.username then return false, "auth"; end
        if session.resource then return false, "constraint"; end -- We don't support binding multiple resources
-       resource = resource or math.random(100000, 99999999); -- FIXME: Clearly we have issues :)
+       resource = resource or uuid_generate();
        --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing
        
        if not hosts[session.host].sessions[session.username] then
diff --git a/util/uuid.lua b/util/uuid.lua
new file mode 100644 (file)
index 0000000..489522a
--- /dev/null
@@ -0,0 +1,9 @@
+
+local m_random = math.random;
+module "uuid"
+
+function uuid_generate()
+       return m_random(0, 99999999);
+end
+
+return _M;
\ No newline at end of file