Comparison

core/stanza_router.lua @ 1143:5bab3eb566ad

stanza_router: Bounce stanzas to/from invalid JIDs with a jid-malformed error
author Matthew Wild <mwild1@gmail.com>
date Wed, 13 May 2009 16:54:46 +0100
parent 967:b021403c5d80
child 1144:fbd65e966316
child 1190:fff8158faae2
comparison
equal deleted inserted replaced
1130:442c87de8e2d 1143:5bab3eb566ad
75 local from_node, from_host, from_resource; 75 local from_node, from_host, from_resource;
76 local to_bare, from_bare; 76 local to_bare, from_bare;
77 if to then 77 if to then
78 node, host, resource = jid_prepped_split(to); 78 node, host, resource = jid_prepped_split(to);
79 if not host then 79 if not host then
80 error("Invalid to JID"); 80 log("warn", "Received stanza with invalid destination JID: %s", to);
81 origin.send(st.error_reply(stanza, "modify", "jid-malformed", "The destination address is invalid: "..to));
82 return;
81 end 83 end
82 to_bare = node and (node.."@"..host) or host; -- bare JID 84 to_bare = node and (node.."@"..host) or host; -- bare JID
83 if resource then to = to_bare.."/"..resource; else to = to_bare; end 85 if resource then to = to_bare.."/"..resource; else to = to_bare; end
84 stanza.attr.to = to; 86 stanza.attr.to = to;
85 end 87 end
86 if from then 88 if from then
89 -- We only stamp the 'from' on c2s stanzas, so we still need to check validity
87 from_node, from_host, from_resource = jid_prepped_split(from); 90 from_node, from_host, from_resource = jid_prepped_split(from);
88 if not from_host then 91 if not from_host then
89 error("Invalid from JID"); 92 log("warn", "Received stanza with invalid source JID: %s", from);
93 origin.send(st.error_reply(stanza, "modify", "jid-malformed", "The source address is invalid: "..from));
94 return;
90 end 95 end
91 from_bare = from_node and (from_node.."@"..from_host) or from_host; -- bare JID 96 from_bare = from_node and (from_node.."@"..from_host) or from_host; -- bare JID
92 if from_resource then from = from_bare.."/"..from_resource; else from = from_bare; end 97 if from_resource then from = from_bare.."/"..from_resource; else from = from_bare; end
93 stanza.attr.from = from; 98 stanza.attr.from = from;
94 end 99 end