comparison mod_carbons/mod_carbons.lua @ 605:5175f6d33470

mod_carbons: Add more debug logging
author Kim Alvefur <zash@zash.se>
date Thu, 09 Feb 2012 13:06:14 +0100
parents ce2798a1bc56
children a9249614b0fe
comparison
equal deleted inserted replaced
604:17e879822700 605:5175f6d33470
42 return -- No carbons for messages of type error or headline 42 return -- No carbons for messages of type error or headline
43 end 43 end
44 44
45 local bare_jid, user_sessions; 45 local bare_jid, user_sessions;
46 local no_carbon_to = {}; 46 local no_carbon_to = {};
47 module:log("debug", "origin (%s) type: %s", tostring(origin), origin.type) 47 module:log("debug", "Message from %s to %s", orig_from, orig_to);
48 if c2s then -- Stanza sent by a local client 48 if c2s then -- Stanza sent by a local client
49 bare_jid = (origin.username.."@"..origin.host) 49 bare_jid = (origin.username.."@"..origin.host)
50 user_sessions = host_sessions[origin.username]; 50 user_sessions = host_sessions[origin.username];
51 else -- Stanza about to be delivered to a local client 51 else -- Stanza about to be delivered to a local client
52 local username, hostname, resource = jid_split(orig_to); 52 local username, hostname, resource = jid_split(orig_to);
53 bare_jid = jid_bare(orig_to); 53 bare_jid = jid_bare(orig_to);
54 user_sessions = host_sessions[username]; 54 user_sessions = host_sessions[username];
55 if resource then 55 if resource then
56 module:log("debug", "Message was to resource %s, it will not get carbon", resource);
56 no_carbon_to[resource] = true; 57 no_carbon_to[resource] = true;
57 elseif user_sessions then 58 elseif user_sessions then
58 local top_resources = user_sessions.top_resources; 59 local top_resources = user_sessions.top_resources;
59 if top_resources then 60 if top_resources then
60 for _, session in ipairs(top_resources) do 61 for _, session in ipairs(top_resources) do
62 module:log("debug", "Not sending carbons to top resource %s", session.resource);
61 no_carbon_to[session.resource] = true; 63 no_carbon_to[session.resource] = true;
62 end 64 end
63 end 65 end
64 end 66 end
65 end 67 end
66 68
67 if not user_sessions then 69 if not user_sessions then
70 module:log("debug", "Skip carbons for offline user");
68 return -- No use in sending carbons to an offline user 71 return -- No use in sending carbons to an offline user
69 end 72 end
70 73
71 if not c2s and stanza:get_child("private", xmlns_carbons) then 74 if not c2s and stanza:get_child("private", xmlns_carbons) then
72 stanza:maptags(function(tag) 75 stanza:maptags(function(tag)
73 return tag.attr.xmlns == xmlns_carbons 76 return tag.attr.xmlns == xmlns_carbons
74 and tag.name == "private" and tag or nil; 77 and tag.name == "private" and tag or nil;
75 end); 78 end);
79 module:log("debug", "Message tagged private, ignoring");
76 return 80 return
77 end 81 end
78 82
79 if not stanza:get_child("forwarded", xmlns_forward) then 83 if not stanza:get_child("forwarded", xmlns_forward) then
80 user_sessions = user_sessions and user_sessions.sessions; 84 user_sessions = user_sessions and user_sessions.sessions;
81 for resource, session in pairs(user_sessions) do 85 for resource, session in pairs(user_sessions) do
82 local full_jid = bare_jid .. "/" .. resource; 86 local full_jid = bare_jid .. "/" .. resource;
87 module:log("debug", "%s wants carbons: %s", session.full_jid, tostring(session.want_carbons));
83 if session.want_carbons then 88 if session.want_carbons then
89 if c2s then
90 module:log("debug", "Session is origin: %s", tostring(session == origin));
91 else
92 module:log("debug", "Session is in ignore list: %s", tostring(no_carbon_to[resource]));
93 end
84 if (c2s and session ~= origin) or (not c2s and not no_carbon_to[resource]) then 94 if (c2s and session ~= origin) or (not c2s and not no_carbon_to[resource]) then
85 local msg = st.clone(stanza); 95 local msg = st.clone(stanza);
86 msg.attr.xmlns = msg.attr.xmlns or "jabber:client"; 96 msg.attr.xmlns = msg.attr.xmlns or "jabber:client";
87 local fwd = st.message{ 97 local fwd = st.message{
88 from = bare_jid, 98 from = bare_jid,
90 type = orig_type, 100 type = orig_type,
91 } 101 }
92 :tag(c2s and "sent" or "received", { xmlns = xmlns_carbons }):up() 102 :tag(c2s and "sent" or "received", { xmlns = xmlns_carbons }):up()
93 :tag("forwarded", { xmlns = xmlns_forward }) 103 :tag("forwarded", { xmlns = xmlns_forward })
94 :add_child(msg); 104 :add_child(msg);
105 module:log("debug", "Sending carbon");
95 core_post_stanza(origin, fwd); 106 core_post_stanza(origin, fwd);
96 end 107 end
97 end 108 end
98 end 109 end
99 end 110 end