diff --git a/sgx-catapult.rb b/sgx-catapult.rb index 8f56dfda1a57a2114e0482207a893a300557d621..8ddfe111e6d7095ac50d96afa724038a19708fc4 100755 --- a/sgx-catapult.rb +++ b/sgx-catapult.rb @@ -47,22 +47,48 @@ module SGXcatapult end end - iq do |i| + iq '/iq/ns:query', :ns => + 'http://jabber.org/protocol/disco#items' do |i, xpath_result| + puts "IQ: #{i.inspect}" - if i.type == :set - puts "received set, likely for jabber:iq:register" + msg = Blather::Stanza::Iq::DiscoItems.new + msg.id = i.id + msg.to = i.from + msg.type = 'result' + + puts "RESPONSE0: #{msg.inspect}" + write_to_stream msg + puts "SENT" + end - # TODO: resilient error handling; what if no query node? + iq '/iq/ns:query', :ns => + 'http://jabber.org/protocol/disco#info' do |i, xpath_result| - qn = i.children.find { |v| v.element_name == "query" } - # TODO: add below check - as-written has unmatched end - i #if qn.namespace.href != 'jabber:iq:register' - # # TODO: error - # puts "weird xmlns: " + qn.namespace.href - # next - #end + puts "IQ: #{i.inspect}" + + msg = Blather::Stanza::Iq::DiscoInfo.new + msg.id = i.id + msg.to = i.from + msg.type = 'result' + + msg.identities = [{:name => + 'Soprani.ca Gateway to XMPP - Catapult', + :type => 'sms-ctplt', :category => 'gateway'}] + msg.features = ["jabber:iq:register", + "jabber:iq:gateway", "jabber:iq:private", + "http://jabber.org/protocol/disco#info", + "http://jabber.org/protocol/commands", + "http://jabber.org/protocol/muc"] + puts "RESPONSE1: #{msg.inspect}" + write_to_stream msg + puts "SENT" + end + iq '/iq/ns:query', :ns => 'jabber:iq:register' do |i, qn| + puts "IQ: #{i.inspect}" + + if i.type == :set xn = qn.children.find { |v| v.element_name == "x" } if xn.nil? @@ -110,42 +136,7 @@ module SGXcatapult write_to_stream msg puts "SENT" - # TODO: implement this (verify/save data, return result) - next - end - - query_node = i.children.find { |v| v.element_name == "query" } - if query_node.namespace.href == - 'http://jabber.org/protocol/disco#items' - - msg = Blather::Stanza::Iq::DiscoItems.new - msg.id = i.id - msg.to = i.from - msg.type = 'result' - - puts "RESPONSE0: #{msg.inspect}" - write_to_stream msg - puts "SENT" - elsif query_node.namespace.href == - 'http://jabber.org/protocol/disco#info' - - msg = Blather::Stanza::Iq::DiscoInfo.new - msg.id = i.id - msg.to = i.from - msg.type = 'result' - - msg.identities = [{:name => - 'Soprani.ca Gateway to XMPP - Catapult', - :type => 'sms-ctplt', :category => 'gateway'}] - msg.features = ["jabber:iq:register", - "jabber:iq:gateway", "jabber:iq:private", - "http://jabber.org/protocol/disco#info", - "http://jabber.org/protocol/commands", - "http://jabber.org/protocol/muc"] - puts "RESPONSE1: #{msg.inspect}" - write_to_stream msg - puts "SENT" - elsif query_node.namespace.href == 'jabber:iq:register' + elsif i.type == :get orig = Blather::Stanza::Iq.new orig.id = i.id orig.to = i.from