ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - balena/elixir-sippet: An Elixir library designed to be used as SIP protocol middleware.
An Elixir library designed to be used as SIP protocol middleware. - balena/elixir-sippet
Visit Site

GitHub - balena/elixir-sippet: An Elixir library designed to be used as SIP protocol middleware.

GitHub - balena/elixir-sippet: An Elixir library designed to be used as SIP protocol middleware.

Sippet

Build Status Coverage Status Docs Status Hex version Hex.pm Code Triagers Badge

An Elixir library designed to write Session Initiation Protocol middleware.

Introduction

SIP is a very flexible protocol that has great depth. It was designed to be a general-purpose way to set up real-time multimedia sessions between groups of participants. It is a text-based protocol modeled on the request/response model used in HTTP. This makes it easy to debug because the messages are relatively easy to construct and easy to see.

Sippet is designed as a simple SIP middleware library, aiming the developer to write any kind of function required to register users, get their availability, check capabilities, setup and manage sessions. On the other hand, Sippet does not intend to provide any feature available in a fully functional SIP UAC/UAS, proxy server, B2BUA, SBC or application; instead, it has only the essential building blocks to build any kind of SIP middleware.

Overview

One of the most central parts of Sippet is the Sippet.Message. Instead of many headers that you end up having to parse by yourself, there's an internal parser written in C++ (an Erlang NIF) that does all the hard work for you. This way, the Sippet.Message.headers is a key-value simple Map where the key is the header name, and the value varies accordingly the header type. For instance, the header :cseq has the form {sequence :: integer, method} where the method is an atom with the method name (like :invite).

Message routing is performed just manipulating Sippet.Message headers; everything else is performed by these layers in a very standard way. That means you may not be able to build some non-standard behaviors, like routing the message to a given host that wasn't correctly added to the topmost Via header.

As Sippet is a simple SIP library, the developer has to understand the protocol very well before writing a middleware. This design decision came up because all attempts to hide any inherent SIP complexity by other frameworks have failed.

There is no support for plugins or hooks, these case be implemented easily with Elixir behaviors and macros, and the developer may custom as he likes. Incoming messages and transport errors are directed to a Sippet.Core module behavior.

Finally, there is no support for many different transport protocols; a simple Sippet.Transports.UDP implementation is provided, which is enough for general purpose SIP middleware. Transport protocols can be implemented quite easily using the same logic of Sippet.Transport.UDP.

Installation

The package can be installed from Hex as:

  1. Add sippet to your list of dependencies in mix.exs:
def deps do
  [{:sippet, "~> 1.0"}]
end
  1. Give a name to your stack and build it:
# Creates a :mystack Sippet instance
Sippet.start_link(name: :mystack)

# The below will create a default UDP transport listening on 0.0.0.0:5060/udp
Sippet.Transports.UDP.start_link(name: :mystack)
  1. Create a Sippet.Core and register it:
defmodule MyCore do
  use Sippet.Core

  def receive_request(incoming_request, server_key) do
    # route the request to your UA or proxy process
  end

  def receive_response(incoming_response, client_key) do
    # route the response to your UA or proxy process
  end

  def receive_error(reason, client_or_server_key) do
    # route the error to your UA or proxy process
  end
end

Sippet.register_core(:mystack, MyCore)

Voilà! The SIP stack will be listening on the indicated address and port, and your MyCore module will receive callbacks from it whenever a SIP message arrives on it.

You may send messages this way:

request = %Message{
  start_line: RequestLine.new(:options, "sip:sip.example.com"),
  headers: %{
    via: [
      {{2, 0}, :udp, {"localhost", 5060}, %{"branch" => Message.create_branch()}}
    ],
    from: {"", URI.parse!("sip:localhost"), %{"tag" => Message.create_tag()}},
    to: {"", URI.parse!("sip:sip.example.com"), %{}},
    cseq: {1, :options},
    user_agent: "Sippet/1.0",
    call_id: Message.create_call_id()
  }
}

Sippet.send(:sippet, request)

If you prefer to specify messages directly in wire format, here you go:

request =
  """
  OPTIONS sip:sip.example.com SIP/2.0
  Via: SIP/2.0/UDP localhost:5060;branch=#{Message.create_branch()}
  From: sip:localhost;tag=#{Message.create_tag()}
  To: sip:sip.example.com
  CSeq: 1 OPTIONS
  User-Agent: Sippet/1.0
  Call-ID: #{Message.create_call_id()}
  """ |> Message.parse!()

Sippet.send(:sippet, request)

Further documentation can found at https://hexdocs.pm/sippet.

Headers format

# Definitions
# ======================================================================================
@type type :: String.t
@type subtype :: String.t
@type token :: String.t
@type name :: String.t
@type scheme :: String.t
@type parameters :: %{String.t => String.t}
@type uri :: Sippet.URI.t
@type major :: integer
@type minor :: integer
@type display_name :: String.t
@type string :: String.t
@type timestamp :: double
@type delay :: double
@type protocol :: atom | String.t
@type method :: atom | String.t


# Header Name             Type
# ======================================================================================
@type headers :: %{
  :accept              => [{{type, subtype}, parameters}, ...],
  :accept_encoding     => [{token, parameters}, ...],
  :accept_language     => [{token, parameters}, ...],
  :alert_info          => [{uri, parameters}, ...],
  :allow               => [token, ...],
  :authentication_info => %{name => value},
  :authorization       => [{scheme, parameters}, ...],
  :call_id             => token,
  :call_info           => [{uri, parameters}, ...],
  :contact             => "*" | [{display_name, uri, parameters}, ...],
  :content_disposition => {token, parameters},
  :content_encoding    => [token, ...],
  :content_language    => [token, ...],
  :content_length      => integer,
  :content_type        => {{type, subtype}, parameters},
  :cseq                => {integer, method},
  :date                => NaiveDateTime.t,
  :error_info          => [{uri, parameters}, ...],
  :expires             => integer,
  :from                => {display_name, uri, parameters},
  :in_reply_to         => [token, ...],
  :max_forwards        => integer,
  :mime_version        => {major, minor},
  :min_expires         => integer,
  :organization        => string,
  :p_asserted_identity => [{display_name, uri, parameters}, ...],
  :priority            => token,
  :proxy_authenticate  => [{scheme, parameters}, ...],
  :proxy_authorization => [{scheme, parameters}, ...],
  :proxy_require       => [token, ...],
  :reason              => [{token, parameters}, ...],
  :record_route        => [{display_name, uri, parameters}, ...],
  :reply_to            => {display_name, uri, parameters},
  :require             => [token, ...],
  :retry_after         => {integer, comment, parameters},
  :route               => [{display_name, uri, parameters}, ...],
  :server              => string,
  :subject             => string,
  :supported           => [token, ...],
  :timestamp           => {timestamp, delay},
  :to                  => {display_name, uri, parameters},
  :unsupported         => [token, ...],
  :user_agent          => string,
  :via                 => [{{major, minor}, protocol, {address, port}, parameters}, ...],
  :warning             => [{integer, agent, text}, ...],
  :www_authenticate    => [{scheme, parameters}, ...],
  String.t             => [String.t, ...]
}

Copyright

Copyright (c) 2016-2020 Guilherme Balena Versiani. See LICENSE for further details.

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory