changeset 734:81de1e446bfe

mod_vjud: Don't break on undefined properties.
author Kim Alvefur <zash@zash.se>
date Sun, 01 Jul 2012 13:51:26 +0200
parents dd3b30c0dc8a
children c1b0f0c33c6a
files mod_vjud/mod_vjud.lua mod_vjud/vcard.lib.lua
diffstat 2 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mod_vjud/mod_vjud.lua	Sun Jul 01 13:15:40 2012 +0200
+++ b/mod_vjud/mod_vjud.lua	Sun Jul 01 13:51:26 2012 +0200
@@ -5,6 +5,7 @@
 local dataforms_new = require "util.dataforms".new;
 local jid_split = require "util.jid".prepped_split;
 local vcard = module:require "vcard";
+local rawget, rawset = rawget, rawset;
 
 local st = require "util.stanza";
 local template = require "util.template";
@@ -48,10 +49,12 @@
 };
 local vCard_mt = {
 	__index = function(t, k)
+		if type(k) ~= "string" then return nil end
 		for i=1,#t do
-			if t[i].name == k then
-				t[k] = t[i];
-				return t[i]
+			local t_i = rawget(t, i);
+			if t_i and t_i.name == k then
+				rawset(t, k, t_i);
+				return t_i;
 			end
 		end
 	end
@@ -60,8 +63,11 @@
 local function get_user_vcard(user)
 	local vCard = dm_load(user, module.host, "vcard");
 	if vCard then
+		module:log("warn", require"util.serialization".serialize(vCard));
 		vCard = st.deserialize(vCard);
+		module:log("warn", require"util.serialization".serialize(vCard));
 		vCard = vcard.from_xep54(vCard);
+		module:log("warn", require"util.serialization".serialize(vCard));
 		return setmetatable(vCard, vCard_mt);
 	end
 end
--- a/mod_vjud/vcard.lib.lua	Sun Jul 01 13:15:40 2012 +0200
+++ b/mod_vjud/vcard.lib.lua	Sun Jul 01 13:51:26 2012 +0200
@@ -227,7 +227,6 @@
 local function from_xep54_item(item)
 	local prop_name = item.name;
 	local prop_def = vCard_dtd[prop_name];
-	if not prop_def then return nil end
 
 	local prop = { name = prop_name };
 
@@ -299,7 +298,7 @@
 	local tags = vCard.tags;
 	local t = {};
 	for i=1,#tags do
-		t[i] = from_xep54_item(tags[i]);
+		t_insert(t, from_xep54_item(tags[i]));
 	end
 	return t
 end
@@ -312,9 +311,7 @@
 		local t = {};
 		local vCards = vCard.tags;
 		for i=1,#vCards do
-			local ti = from_xep54_vCard(vCards[i]);
-			t[i] = ti;
-			--t[ti.name] = ti;
+			t[i] = from_xep54_vCard(vCards[i]);
 		end
 		return t
 	elseif vCard.name == "vCard" then -- A single vCard