Sinatra like DSL for SIP Servlets
Ruby Java
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
src/main
tasks
.gitignore
.rvmrc
LICENSE
README.textile
Rakefile
pom.xml

README.textile

DISCLAIMER

This project continues to leave at http://www.cipango.org.
The repository is at http://code.google.com/p/cipango/source/browse/#svn/trunk/extras/sipatra.

SIPATRA

Sipatra is a simple Sinatra like Ruby DSL for SIP Servlets. It’s heavily inspired from Sinatra and was adapted only in those areas that were required by differences between the HTTP and SIP protocols. Sipatra is written is JRuby and targets SIP Servlet 1.1 compatible application servers

Sipatra is a work in progress. The Ruby DSL may change without notice.

Handlers

In Sipatra an handler is a SIP method paired with an URI matching pattern and some conditions. Each handler is associated with a block:

invite 'sip:standard@.*' do
    proxy "sip:0123456789@#{message.requestURI.host}"
    puts "VIA    : '#{headers[:Via].join(", ")}'"
    puts "CONTACT: '#{header['Contact']}'"
    
    send_response 200, "OK", 'X-Header' => 'Foo'
end

register do
    proxy
end

Those handlers have to be put in a file called WEB-INF/jruby/application.rb and you need to add the following declaration to your WEB-INF/sip.xml. Handlers exist for the following SIP methods: ACK, BYE, CANCEL, INFO, INVITE, MESSAGE, NOTIFY, OPTIONS, PRACK, PUBLISH, REFER, REGISTER, SUBSCRIBE, UPDATE (http://en.wikipedia.org/wiki/List_of_SIP_request_methods).

Helper methods like send_response are available to handler writers in order to reduce the amount of code necessary for common tasks.

To use Sipatra in your SIP applications, just add the following declaration to you WEB-INF/sip.xml file together with the dependencies listed below.

  <servlet>
      <servlet-name>jruby</servlet-name>
      <servlet-class>org.cipango.jruby.JRubyServlet</servlet-class>
      <load-on-startup/>
  </servlet>

Helper methods

Handlers have access to helper methods which permit to concisely implement common SIP Servlet call patterns.

send_response generates a response and sends it:

send_response :ok
send_response :not_found, "Number was not found"
send_response :ok, :Date => Time::now.httpdate
send_response :ok do |res|
 res.setHeader("Date", Time::now.httpdate)
end

create_address creates an address header:

create_address('sip:12345@domain.com')
create_address('sip:12345@domain.com', :expires => 1234, :display_name => 'Foo')

Dependencies

In order to use the cipango-jruby-1.0-SNAPSHOT.jar you also need to put those jars into your WEB-INF/lib directory.

Sample application

A very simple, yet functionnal, sample application is available.