Changeset

551:53dc98ffde16

Automated merge with http://waqas.ath.cx/
author Matthew Wild <mwild1@gmail.com>
date Thu, 04 Dec 2008 19:21:50 +0000
parents 550:56bdfae9e4ea (diff) 548:c80137472280 (current diff)
children 553:08db6883bbc5
files
diffstat 3 files changed, 11 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_register.lua	Thu Dec 04 18:49:00 2008 +0000
+++ b/plugins/mod_register.lua	Thu Dec 04 19:21:50 2008 +0000
@@ -51,7 +51,7 @@
 				end
 				-- TODO datamanager should be able to delete all user data itself
 				datamanager.store(session.username, session.host, "roster", nil);
-				datamanager.store(session.username, session.host, "vCard", nil);
+				datamanager.store(session.username, session.host, "vcard", nil);
 				datamanager.store(session.username, session.host, "private", nil);
 				datamanager.store(session.username, session.host, "offline", nil);
 				local bare = session.username.."@"..session.host;
--- a/plugins/mod_vcard.lua	Thu Dec 04 18:49:00 2008 +0000
+++ b/plugins/mod_vcard.lua	Thu Dec 04 19:21:50 2008 +0000
@@ -39,10 +39,10 @@
 					if to then
 						local node, host = jid_split(to);
 						if hosts[host] and hosts[host].type == "local" then
-							vCard = st.deserialize(datamanager.load(node, host, "vCard")); -- load vCard for user or server
+							vCard = st.deserialize(datamanager.load(node, host, "vcard")); -- load vCard for user or server
 						end
 					else
-						vCard = st.deserialize(datamanager.load(session.username, session.host, "vCard"));-- load user's own vCard
+						vCard = st.deserialize(datamanager.load(session.username, session.host, "vcard"));-- load user's own vCard
 					end
 					if vCard then
 						session.send(st.reply(stanza):add_child(vCard)); -- send vCard!
@@ -51,7 +51,7 @@
 					end
 				elseif stanza.attr.type == "set" then
 					if not to or to == session.username.."@"..session.host then
-						if datamanager.store(session.username, session.host, "vCard", st.preserialize(stanza.tags[1])) then
+						if datamanager.store(session.username, session.host, "vcard", st.preserialize(stanza.tags[1])) then
 							session.send(st.reply(stanza));
 						else
 							-- TODO unable to write file, file may be locked, etc, what's the correct error?
@@ -66,8 +66,8 @@
 		end);
 
 local feature_vcard_attr = { var='vcard-temp' };
-module:add_event_hook("stream-features", 
-					function (session, features)												
+module:add_event_hook("stream-features",
+					function (session, features)
 						if session.type == "c2s" then
 							features:tag("feature", feature_vcard_attr):up();
 						end
--- a/util/datamanager.lua	Thu Dec 04 18:49:00 2008 +0000
+++ b/util/datamanager.lua	Thu Dec 04 19:21:50 2008 +0000
@@ -30,21 +30,12 @@
 local error = error;
 local next = next;
 local t_insert = table.insert;
-
-local indent = function(f, i)
-	for n = 1, i do
-		f:write("\t");
-	end
-end
-
-local data_path = "data";
+local append = require "util.serialization".append;
 
 module "datamanager"
 
-
 ---- utils -----
 local encode, decode;
-
 do 
 	local urlcodes = setmetatable({}, { __index = function (t, k) t[k] = char(tonumber("0x"..k)); return t[k]; end });
 
@@ -57,39 +48,9 @@
 	end
 end
 
-local function basicSerialize (o)
-	if type(o) == "number" or type(o) == "boolean" then
-		return tostring(o);
-	else -- assume it is a string -- FIXME make sure it's a string. throw an error otherwise.
-		return (format("%q", tostring(o)):gsub("\\\n", "\\n"));
-	end
-end
-
-
-local function simplesave (f, o, ind)
-	if type(o) == "number" then
-		f:write(o)
-	elseif type(o) == "string" then
-		f:write((format("%q", o):gsub("\\\n", "\\n")))
-	elseif type(o) == "table" then
-		f:write("{\n")
-		for k,v in pairs(o) do
-			indent(f, ind);
-			f:write("[", basicSerialize(k), "] = ")
-			simplesave(f, v, ind+1)
-			f:write(",\n")
-		end
-		indent(f, ind-1);
-		f:write("}")
-	elseif type(o) == "boolean" then
-		f:write(o and "true" or "false");
-	else
-		error("cannot serialize a " .. type(o))
-	end
-end
-
 ------- API -------------
 
+local data_path = "data";
 function set_data_path(path)
 	data_path = path;
 end
@@ -131,7 +92,7 @@
 		return;
 	end
 	f:write("return ");
-	simplesave(f, data, 1);
+	append(f, data);
 	f:close();
 	if not next(data) then -- try to delete empty datastore
 		os_remove(getpath(username, host, datastore));
@@ -150,7 +111,7 @@
 		return;
 	end
 	f:write("item(");
-	simplesave(f, data, 1);
+	append(f, data);
 	f:write(");\n");
 	f:close();
 	return true;
@@ -168,7 +129,7 @@
 	end
 	for _, d in ipairs(data) do
 		f:write("item(");
-		simplesave(f, d, 1);
+		append(f, d);
 		f:write(");\n");
 	end
 	f:close();