Module OverSIP::SIP::Core

The module OverSIP::SIP::Core includes instance methods into the OverSIP::SIP::Request class. Those methods add SIP core features.

Module instance methods

create_transaction

Creates a server transaction (INVITE or non-INVITE) for the received SIP request. It returns nil if the method is CANCEL or ACK, and false in case a server transaction already exists for the current SIP request.

NOTE: A server transaction is automatically added by OverSIP when forwarding a SIP request by calling the route() method of an OverSIP::SIP::Proxy instance.

Example

request.create_transaction

check_max_forwards(value)

Checks the Max-Forwards header value of the received SIP request against the given value:

  • If the request has a Max-Forwards value greater than 0 and greater than the given value, then the new Max-Forwards value becomes the given value. The method returns true.
  • If the request has a Max-Forwards value greater than 0 but equal or less than the given value, then the new Max-Forwards value becomes the original value minus 1. The method returns true.
  • If the request has a Max-Forwards value equal to 0 then OverSIP automatically replies a 483 “Too Many Hops” and the method returns false (it is the responsability of the user not to follow the logic script for this request by calling return).
  • If the request has no Max-Forwards header then such a header is added with the given value and the method returns true.

Parameters

value
The value (Fixnum) for the Max-Forwards check.

Example

# Check Max-Forwards value (max 10):
unless request.check_max_forwards 10
  log_notice "request with Max-Forwards 0 rejected"
  return
end

loose_route

Performs the Loose-Routing mechanism as stated in RFC 3261. It also follows Outbound rules (as stated in RFC 5626) for applying Outbound usage. The method performs the following steps:

  • Removes all the Route headers (from top to bottom) whose URI hostport component points to a local domain or address (until a non matching Route is found).
  • Checks whether the SIP request is asking for incoming or outgoing Outbound support (section 5.3 in RFC 5626).
  • Returns false if the request had no Route headers.
  • Returns true if it is an in-dialog request and the top Route pointed to a local domain or address.
  • Returns false if it is an in-dialog request and the top Route did not point to a local domain or address.
  • Returns true if it is an initial request and some Route headers remain after the first step (so they don’t point to a local domain or address). NOTE: This means that the initial request has pre-loaded Route headers (which could be dangerous).
  • Returns false if it is an initial request and no Route headers remain after the first step (so all of them pointed to a local domain or address).

Example

For a full example code check the OverSIP::SipEvents.on_request section in the default server.rb file.

destination_myself?

Returns true if the Request URI points to a local domain or address, false otherwise.

Example

if request.destination_myself?
  log_notice "request for myself, reply 404"
  request.reply 404, "I'm here but cannot do more with your request"
  return
end

fix_nat

If the request arrives to OverSIP via UDP then “Symmetric Response Routing” (RFC 3581) is assumed regardless the top Via header does not contain a ;rport parameter.

For any received transport (including UDP) this method forces Outbound mechanism (RFC 5626) even if the request does not indicate support for it.

NOTE: Outbound is just forced when the following requirements are satisfied:

  • It is an initial SIP request.
  • It has a single Via value (so the request has not been previously forwarded by another SIP proxy).
  • The SIP method is INVITE, REGISTER, SUBSCRIBE or REFER.

Example

# If the request comes via WS or WSS transport then always force Outbound:
if request.websocket?
  request.fix_nat
end