Skip to content
This repository has been archived by the owner on Aug 14, 2020. It is now read-only.

Commit

Permalink
New design of OverSIP::Modules::OutboundMangling module: `add_outbo…
Browse files Browse the repository at this point in the history
…und_to_contact()` now requires passing an `OverSIP::SIP::Proxy` as argument rather than a request, and it internally adds the callback to the 2XX response (for reverting the custom ;ov-ob param) so `remove_outbound_from_contact()` is no longer required and has been removed.
  • Loading branch information
ibc committed Feb 4, 2013
1 parent 774de3b commit e58974f
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions lib/oversip/modules/outbound_mangling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,27 @@ module OutboundMangling

@log_id = "OutboundMangling module"

def self.add_outbound_to_contact request
if request.contact and request.connection_outbound_flow_token
log_system_debug "performing Contact mangling (adding ;ov-ob Outbound param) for #{request.log_id}" if $oversip_debug
def self.add_outbound_to_contact proxy
unless proxy.is_a? ::OverSIP::SIP::Proxy
raise ::OverSIP::RuntimeError, "proxy must be a OverSIP::SIP::Proxy instance"
end

# Add the ;ov-ob param to the Contact URI.
request.contact.set_param "ov-ob", request.connection_outbound_flow_token
return true
else
return false
proxy.on_target do |target|
request = proxy.request
# Just act in case the request has a single Contact, its connection uses Outbound
# and no ;ov-ob param exists in Contact URI.
if request.contact and request.connection_outbound_flow_token and not request.contact.has_param? "ov-ob"
log_system_debug "performing Contact mangling (adding ;ov-ob Outbound param) for #{request.log_id}" if $oversip_debug

request.contact.set_param "ov-ob", request.connection_outbound_flow_token

proxy.on_success_response do |response|
if (contacts = response.headers["Contact"])
log_system_debug "reverting original Contact value (removing ;ov-ob Outbound param) from response" if $oversip_debug
contacts.each { |contact| contact.gsub! /;ov-ob=[_\-0-9A-Za-z]+/, "" }
end
end
end
end
end

Expand All @@ -39,22 +51,6 @@ def self.extract_outbound_from_ruri request
end
end

def self.remove_outbound_from_contact message
unless message.is_a? ::OverSIP::SIP::Message
raise ::OverSIP::RuntimeError, "message must be a OverSIP::SIP::Request or OverSIP::SIP::Response"
end

if (contacts = message.headers["Contact"])
log_system_debug "reverting original Contact value (removing ;ov-ob Outbound param) for response" if $oversip_debug
contacts.each do |contact|
contact.gsub! /;ov-ob=[_\-0-9A-Za-z]+/, ""
end
return true
else
return false
end
end

end # module OutboundMangling

end

0 comments on commit e58974f

Please sign in to comment.