From 60832f5146821bac8a1e6766f32d43dc8806010c Mon Sep 17 00:00:00 2001 From: Denver Gingerich Date: Sat, 11 Apr 2020 23:49:37 +0000 Subject: [PATCH] rip out Jingle support: can't test & broken anyway --- sgx-bwmsgsv2.rb | 192 ------------------------------------------------ 1 file changed, 192 deletions(-) diff --git a/sgx-bwmsgsv2.rb b/sgx-bwmsgsv2.rb index b085587053f0163d65cf865044fdb84d38986336..20a558d804c620f8e4489ef8f5dc132cf3ce21b1 100755 --- a/sgx-bwmsgsv2.rb +++ b/sgx-bwmsgsv2.rb @@ -84,9 +84,6 @@ end module SGXbwmsgsv2 extend Blather::DSL - @jingle_sids = {} - @jingle_fnames = {} - @partial_data = {} @client = SGXClient.new @gateway_features = [ "http://jabber.org/protocol/disco#info", @@ -405,14 +402,6 @@ module SGXbwmsgsv2 def self.user_cap_features [ "urn:xmpp:receipts", - "urn:xmpp:jingle:1", "urn:xmpp:jingle:transports:ibb:1", - - # TODO: add more efficient file transfer mechanisms - #"urn:xmpp:jingle:transports:s5b:1", - - # TODO: MUST add all reasonable vers of file-transfer - #"urn:xmpp:jingle:apps:file-transfer:4" - "urn:xmpp:jingle:apps:file-transfer:3" ] end @@ -475,187 +464,6 @@ module SGXbwmsgsv2 write_to_stream msg end - iq '/iq/ns:jingle', ns: 'urn:xmpp:jingle:1' do |i, jn| - puts "IQj: #{i.inspect}" - - if jn[0]['action'] == 'transport-accept' - puts "REPLY0: #{i.reply.inspect}" - write_to_stream i.reply - next - elsif jn[0]['action'] == 'session-terminate' - # TODO: unexpected (usually we do this; handle?) - puts "TERMINATED" - next - elsif jn[0]['action'] == 'transport-info' - # TODO: unexpected, but should handle in a nice way - puts "FAIL!!!" - next - elsif i.type == :error - # TODO: do something, maybe terminating the connection - puts 'ERROR!!!' - next - end - - # TODO: should probably confirm we got session-initiate here - - write_to_stream i.reply - puts "RESPONSE8: #{i.reply.inspect}" - - msg = Blather::Stanza::Iq.new :set - msg.to = i.from - msg.from = i.to - - cn = jn.children.find { |v| v.element_name == "content" } - puts 'CN-name: ' + cn['name'] - puts 'JN-sid: ' + jn[0]['sid'] - - ibb_found = false - last_sid = '' - cn.children.each do |child| - if child.element_name == 'transport' - puts 'TPORT: ' + child.namespace.href - last_sid = child['sid'] - if 'urn:xmpp:jingle:transports:ibb:1' == - child.namespace.href - - ibb_found = true - break - end - end - end - - j = Nokogiri::XML::Node.new 'jingle', msg.document - j['xmlns'] = 'urn:xmpp:jingle:1' - j['sid'] = jn[0]['sid'] - msg.add_child(j) - - content = Nokogiri::XML::Node.new 'content', msg.document - content['name'] = cn['name'] - content['creator'] = 'initiator' - j.add_child(content) - - transport = Nokogiri::XML::Node.new 'transport', msg.document - # TODO: make block-size more variable and/or dependent on sender - transport['block-size'] = '4096' - transport['xmlns'] = 'urn:xmpp:jingle:transports:ibb:1' - if ibb_found - transport['sid'] = last_sid - j['action'] = 'session-accept' - j['responder'] = i.from - - dsc = Nokogiri::XML::Node.new 'description', msg.document - dsc['xmlns'] = 'urn:xmpp:jingle:apps:file-transfer:3' - content.add_child(dsc) - else - # for Conversations - it tries s5b even if caps ibb-only - transport['sid'] = SecureRandom.uuid - j['action'] = 'transport-replace' - j['initiator'] = i.from - end - content.add_child(transport) - - @jingle_sids[transport['sid']] = jn[0]['sid'] - - # TODO: save as well? Gajim sends, Conversations does not - # TODO: save/validate with eventual full received length - fname = - cn - .children.find { |v| v.element_name == "description" } - .children.find { |w| w.element_name == "offer" } - .children.find { |x| x.element_name == "file" } - .children.find { |y| y.element_name == "name" } - @jingle_fnames[transport['sid']] = fname.text - - puts "RESPONSE9: #{msg.inspect}" - write_to_stream msg - end - - iq '/iq/ns:open', ns: 'http://jabber.org/protocol/ibb' do |i, on| - puts "IQo: #{i.inspect}" - - @partial_data[on[0]['sid']] = '' - write_to_stream i.reply - end - - iq '/iq/ns:data', ns: 'http://jabber.org/protocol/ibb' do |i, dn| - @partial_data[dn[0]['sid']] += Base64.decode64(dn[0].text) - write_to_stream i.reply - end - - iq '/iq/ns:close', ns: 'http://jabber.org/protocol/ibb' do |i, cn| - puts "IQc: #{i.inspect}" - write_to_stream i.reply - - EMPromise.all([ - validate_num(i.to.node), - fetch_catapult_cred_for(i.from) - ]).then { |(num_dest, creds)| - # Gajim bug: has Jingle (not transport) sid; fix later - if not @jingle_fnames.key? cn[0]['sid'] - puts 'ERROR: Not found in filename map: ' + cn[0]['sid'] - - next EMPromise.reject(:done) - # TODO: in case only Gajim's bug fixed, add map: - #cn[0]['sid'] = @jingle_tsids[cn[0]['sid']] - end - - # upload cached data to server (before success reply) - media_name = - "#{Time.now.utc.iso8601}_#{SecureRandom.uuid}"\ - "_#{@jingle_fnames[cn[0]['sid']]}" - puts 'name to save: ' + media_name - - path = "/v1/users/#{creds.first}/media/#{media_name}" - - EMPromise.all([ - call_catapult( - *creds[1..2], - :put, - path, - @partial_data[cn[0]['sid']] - ).catch { - EMPromise.reject([ - :cancel, 'internal-server-error' - ]) - }, - to_catapult( - i, - "https://api.catapult.inetwork.com/" + - path, - num_dest, - *creds - ) - ]) - }.then { - @partial_data[cn[0]['sid']] = '' - - # received the complete file so now close the stream - msg = Blather::Stanza::Iq.new :set - msg.to = i.from - msg.from = i.to - - j = Nokogiri::XML::Node.new 'jingle', msg.document - j['xmlns'] = 'urn:xmpp:jingle:1' - j['action'] = 'session-terminate' - j['sid'] = @jingle_sids[cn[0]['sid']] - msg.add_child(j) - - r = Nokogiri::XML::Node.new 'reason', msg.document - s = Nokogiri::XML::Node.new 'success', msg.document - r.add_child(s) - j.add_child(r) - - puts 'RESPONSE1: ' + msg.inspect - write_to_stream msg - }.catch { |e| - if e.is_a?(Array) && e.length == 2 - write_to_stream error_msg(i.reply, nil, *e) - elsif e != :done - EMPromise.reject(e) - end - } - end - iq '/iq/ns:query', ns: 'http://jabber.org/protocol/disco#info' do |i| # respond to capabilities request for an sgx-bwmsgsv2 number JID if i.to.node