Merge 0.8->trunk
authorMatthew Wild <mwild1@gmail.com>
Sat, 8 Jan 2011 23:21:28 +0000 (23:21 +0000)
committerMatthew Wild <mwild1@gmail.com>
Sat, 8 Jan 2011 23:21:28 +0000 (23:21 +0000)
net/adns.lua
plugins/mod_bosh.lua
plugins/mod_storage_sql.lua

index a3b07b09dc9b7ca4e87a5a4b495c3767f458c42c..cd69a627e044f69182ee59d5f0586ba1d6e6a17a 100644 (file)
@@ -79,7 +79,8 @@ function new_async_socket(sock, resolver)
        handler.connect = function (_, ...) return sock:connect(...) end
        --handler.send = function (_, data) _:write(data);  return _.sendbuffer and _.sendbuffer(); end
        handler.send = function (_, data)
-               log("debug", "Sending DNS query to %s", sock:getpeername());
+               local getpeername = sock.getpeername;
+               log("debug", "Sending DNS query to %s", (getpeername and getpeername(sock)) or "<unconnected>");
                return sock:send(data);
        end
        return handler;
index b9152c9f6caa6cf26351e8b01334433f9d44a8cf..a747f3cbd4a09d121e08189c327faa13bb0dedf2 100644 (file)
@@ -274,6 +274,7 @@ function stream_callbacks.streamopened(request, attr)
                                t_insert(session.send_buffer, tostring(s));
                                log("debug", "There are now %d things in the send_buffer", #session.send_buffer);
                        end
+                       return true;
                end
                
                -- Send creation response
index 63f75991992cd8c860a47d94eeeee1180d4dc163..3f28307d3046b34ad80746cf93d169bc14aff715 100644 (file)
@@ -57,17 +57,19 @@ do -- process options to get a db connection
        dbh:autocommit(false); -- don't commit automatically
        connection = dbh;
        
-       if params.driver == "SQLite3" then -- auto initialize
-               local stmt = assert(connection:prepare("SELECT COUNT(*) FROM `sqlite_master` WHERE `type`='table' AND `name`='Prosody';"));
-               local ok = assert(stmt:execute());
-               local count = stmt:fetch()[1];
-               if count == 0 then
-                       local stmt = assert(connection:prepare("CREATE TABLE `Prosody` (`host` TEXT, `user` TEXT, `store` TEXT, `key` TEXT, `type` TEXT, `value` TEXT);"));
-                       assert(stmt:execute());
-                       module:log("debug", "Initialized new SQLite3 database");
+       -- Automatically create table, ignore failure (table probably already exists)
+       local create_sql = "CREATE TABLE `prosody` (`host` TEXT, `user` TEXT, `store` TEXT, `key` TEXT, `type` TEXT, `value` TEXT);";
+       if params.driver == "PostgreSQL" then
+               create_sql = create_sql:gsub("`", "\"");
+       end
+       
+       local stmt = connection:prepare(create_sql);
+       if stmt then
+               local ok = stmt:execute();
+               local commit_ok = connection:commit();
+               if ok and commit_ok then
+                       module:log("info", "Initialized new %s database with prosody table", params.driver);
                end
-               assert(connection:commit());
-               --print("===", json.encode())
        end
 end
 
@@ -124,7 +126,7 @@ local function commit(...)
 end
 
 local function keyval_store_get()
-       local stmt, err = getsql("SELECT * FROM `Prosody` WHERE `host`=? AND `user`=? AND `store`=?");
+       local stmt, err = getsql("SELECT * FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=?");
        if not stmt then return nil, err; end
        
        local haveany;
@@ -144,7 +146,7 @@ local function keyval_store_get()
        return commit(haveany and result or nil);
 end
 local function keyval_store_set(data)
-       local affected, err = setsql("DELETE FROM `Prosody` WHERE `host`=? AND `user`=? AND `store`=?");
+       local affected, err = setsql("DELETE FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=?");
        
        if data and next(data) ~= nil then
                local extradata = {};
@@ -152,7 +154,7 @@ local function keyval_store_set(data)
                        if type(key) == "string" and key ~= "" then
                                local t, value = serialize(value);
                                if not t then return rollback(t, value); end
-                               local ok, err = setsql("INSERT INTO `Prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", key, t, value);
+                               local ok, err = setsql("INSERT INTO `prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", key, t, value);
                                if not ok then return rollback(ok, err); end
                        else
                                extradata[key] = value;
@@ -161,7 +163,7 @@ local function keyval_store_set(data)
                if next(extradata) ~= nil then
                        local t, extradata = serialize(extradata);
                        if not t then return rollback(t, extradata); end
-                       local ok, err = setsql("INSERT INTO `Prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", "", t, extradata);
+                       local ok, err = setsql("INSERT INTO `prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", "", t, extradata);
                        if not ok then return rollback(ok, err); end
                end
        end
@@ -182,7 +184,7 @@ function keyval_store:set(username, data)
 end
 
 local function map_store_get(key)
-       local stmt, err = getsql("SELECT * FROM `Prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", key or "");
+       local stmt, err = getsql("SELECT * FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", key or "");
        if not stmt then return nil, err; end
        
        local haveany;
@@ -202,13 +204,13 @@ local function map_store_get(key)
        return commit(haveany and result[key] or nil);
 end
 local function map_store_set(key, data)
-       local affected, err = setsql("DELETE FROM `Prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", key or "");
+       local affected, err = setsql("DELETE FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", key or "");
        
        if data and next(data) ~= nil then
                if type(key) == "string" and key ~= "" then
                        local t, value = serialize(data);
                        if not t then return rollback(t, value); end
-                       local ok, err = setsql("INSERT INTO `Prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", key, t, value);
+                       local ok, err = setsql("INSERT INTO `prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", key, t, value);
                        if not ok then return rollback(ok, err); end
                else
                        -- TODO non-string keys
@@ -238,10 +240,10 @@ function list_store:scan(username, from, to, jid, typ)
        local cols = {"from", "to", "jid", "typ"};
        local vals = { from ,  to ,  jid ,  typ };
        local stmt, err;
-       local query = "SELECT * FROM `ProsodyArchive` WHERE `host`=? AND `user`=? AND `store`=?";
+       local query = "SELECT * FROM `prosodyarchive` WHERE `host`=? AND `user`=? AND `store`=?";
        
        query = query.." ORDER BY time";
-       --local stmt, err = getsql("SELECT * FROM `Prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", key or "");
+       --local stmt, err = getsql("SELECT * FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", key or "");
        
        return nil, "not-implemented"
 end