Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

More fixes. add, remove, block and unblock contact

  • Loading branch information...
commit 71480325a4f9756052dcf6c67f30ffb8c9877a89 1 parent 6825aa1
@asterite asterite authored
View
18 lib/msn/messenger.rb
@@ -32,13 +32,25 @@ def set_online_status(status)
end
end
- def add_contact(email, display_name = email)
- @notification_server.add "AL", email, display_name
+ def add_contact(email)
+ send_contact_command email, 'ADL', '1'
end
def remove_contact(email)
+ send_contact_command email, 'RML', '1'
+ end
+
+ def block_contact(email)
+ send_contact_command email, 'RML', '2'
+ end
+
+ def unblock_contact(email)
+ send_contact_command email, 'ADL', '2'
+ end
+
+ def send_contact_command(email, command, list)
username, domain = email.split '@', 2
- @notification_server.send_payload_command "RML", %Q(<ml><d n="#{domain}"><c n="#{username}" t="1" l="1" /></d></ml>)
+ @notification_server.send_payload_command_and_wait command, %Q(<ml><d n="#{domain}"><c n="#{username}" t="1" l="#{list}" /></d></ml>)
end
def on_ready(&handler)
View
4 lib/msn/nexus.rb
@@ -29,8 +29,8 @@ def get_binary_secret(username, password)
xml = Nokogiri::XML(response)
rstr = xml.xpath "//wst:RequestSecurityTokenResponse[wsp:AppliesTo/wsa:EndpointReference/wsa:Address!='http://Passport.NET/tb']", Namespaces
- token = rstr.xpath("wst:RequestedSecurityToken/wsse:BinarySecurityToken[@Id='Compact1']", Namespaces).text
- secret = rstr.xpath("wst:RequestedProofToken/wst:BinarySecret", Namespaces).text
+ token = rstr.xpath("wst:RequestedSecurityToken/wsse:BinarySecurityToken[@Id='Compact1']", Namespaces).first.text
+ secret = rstr.xpath("wst:RequestedProofToken/wst:BinarySecret", Namespaces).first.text
[token, secret]
end
View
26 lib/msn/notification_server.rb
@@ -2,7 +2,6 @@ class Msn::NotificationServer < EventMachine::Connection
include Msn::Protocol
attr_reader :messenger
- attr_reader :display_name
attr_reader :guid
def initialize(messenger)
@@ -10,12 +9,13 @@ def initialize(messenger)
@guid = Guid.new.to_s
@switchboards = {}
- on_event 'ADD' do |header|
- if header[3] =~ /\A\d+\Z/
- messenger.contact_request header[4], header[5]
- else
- messenger.contact_request header[3], header[4]
- end
+ on_event 'ADL' do |header, data|
+ data = Nokogiri::XML(data)
+ domain = data.xpath('//ml/d').first['n']
+ c = data.xpath('//ml/d/c').first
+ username = c['n']
+ display_name = c['f']
+ messenger.contact_request "#{username}@#{domain}", display_name
end
end
@@ -74,6 +74,14 @@ def login_to_nexus(policy, nonce)
nexus = Msn::Nexus.new policy, nonce
token, return_value = nexus.login messenger.username, messenger.password
+ first_msg = true
+ on_event('MSG') do
+ if first_msg
+ first_msg = false
+ messenger.ready
+ end
+ end
+
on_event('RNG') do |header|
switchboard = create_switchboard header[5], header[2]
switchboard.ans username_guid, header[4], header[1]
@@ -83,10 +91,6 @@ def login_to_nexus(policy, nonce)
if response[2] != "OK"
raise "Login failed (3)"
end
-
- messenger.ready
-
- @display_name = CGI.unescape response[4]
end
def create_switchboard(email, host_and_port)
View
40 lib/msn/protocol.rb
@@ -16,22 +16,36 @@ def receive_line(line)
answer_challenge pieces[2]
when 'RNG'
handle_event pieces
- when 'MSG', 'NOT', 'GCF', 'ADL', 'RML'
- @header = pieces
-
- size = pieces.last.to_i
- set_binary_mode size
+ when 'MSG', 'NOT', 'GCF', 'UBX'
+ handle_payload_command pieces
when 'QRY'
# ignore
- else
- if fiber = @command_fibers.delete(pieces[1].to_i)
- fiber.resume pieces
+ when 'ADL', 'RML'
+ if pieces[2] == 'OK'
+ handle_normal_command pieces
else
- handle_event pieces
+ handle_payload_command pieces
end
+ else
+ handle_normal_command pieces
end
end
+ def handle_normal_command(pieces)
+ if fiber = @command_fibers.delete(pieces[1].to_i)
+ fiber.resume pieces
+ else
+ handle_event pieces
+ end
+ end
+
+ def handle_payload_command(pieces)
+ @header = pieces
+
+ size = pieces.last.to_i
+ set_binary_mode size
+ end
+
def receive_binary_data(data)
puts "<<* #{data}" if Msn::Messenger.debug
@@ -68,6 +82,14 @@ def send_payload_command(command, *args)
send_command_internal "#{command} #{@trid} #{args.join ' '}\r\n#{payload}"
end
+ def send_payload_command_and_wait(command, *args)
+ @command_fibers[@trid] = Fiber.current
+
+ send_payload_command command, *args
+
+ Fiber.yield
+ end
+
def send_command_internal(text)
puts ">> #{text}" if Msn::Messenger.debug
send_data text
Please sign in to comment.
Something went wrong with that request. Please try again.