Sofia-SIP

Rust bindings for Sofia-SIP (Alpha stage).

Usage

Add the following to your Cargo.toml:

toml [dependencies] sofia-sip = "0.1.0"

Example

```rust use sofia_sip::{Handle, Nua, NuaEvent, Sip, Tag, TagBuilder};

fn main() { /* A B |-------MESSAGE----->| |<--------200--------| | |

                       ______(NETWORK)_____
                      /                    \
A                 NUA STACK (A)
|                     |
|    nua::handle( )   |
|-------------------->|
|                     |
|  handle::message()  |
|------------------->[_]      [MESSAGE]
|                    [_]------------------>
|                    [_]
|                    [_]
|                    [_]      [200 OK]
|    ReplyMessage    [_]<------------------
|<------------------ [_]
|                     |
|                     |
*/

/* bind on :5080 */
let sip_bind_url = "sip:*:5080";

/* send to a SIP contact running in 192.168.0.51 on default port */
let sip_to_url = "sip:600@192.168.0.51:5060";

/* build params for Nua::create */
let tags = TagBuilder::default()
    .tag(Tag::NuUrl(sip_bind_url).unwrap())
    .collect();

/* create NUA stack */
let mut nua = Nua::create(tags).unwrap();

/*
Handling of the events coming from NUA stack is done
in the callback function that is registered for NUA stack
*/
nua.callback(
    |nua: &mut Nua,
     event: NuaEvent,
     status: u32,
     phrase: String,
     _handle: Option<&Handle>,
     sip: Sip,
     _tags: Vec<Tag>| {
        println!("({:?}) status: {} | {}", &event, status, &phrase);
        match event {
            NuaEvent::ReplyShutdown => { /* received when NUA stack is about to shutdown */ }
            NuaEvent::IncomingMessage => {
                /* incoming NEW message */
                println!("Received MESSAGE: {} {}", status, &phrase);
                println!("From: {}", sip.from());
                println!("To: {}", sip.to());
                println!("Subject: {}", sip.subject());
                println!("ContentType: {}", sip.content_type());
                println!("Payload: {:?}", sip.payload().as_utf8_lossy());

                /* quit after new message */
                nua.quit();
            }
            NuaEvent::ReplyMessage => {
                /* quit if response != 200 */
                if status != 202 {
                    nua.quit();
                }
            }
            _ => {

            }
        }
    },
);

/* Message to be send */
let my_message = "Hi Sofia-SIP-sys";

/* build params for Handle::create */
let tags = TagBuilder::default()
    .tag(Tag::SipTo(sip_to_url).unwrap())
    .tag(Tag::NuUrl(sip_to_url).unwrap())
    .collect();

/* create operation handle */
let handle = Handle::create(&nua, tags).unwrap();

/* build params for handle.message() */
let tags = TagBuilder::default()
    .tag(Tag::SipSubject("NUA").unwrap())
    .tag(Tag::SipTo(sip_to_url).unwrap())
    .tag(Tag::NuUrl(sip_to_url).unwrap())
    .tag(Tag::SipContentType("text/plain").unwrap())
    .tag(Tag::SipPayloadString(my_message).unwrap())
    .collect();

/* The message() function enqueue a SIP MESSAGE on NUA STACK */
handle.message(tags);

/* enter main loop for processing of messages */
println!("enter the main loop");
nua.run();
println!("the main loop exit");

}

```

Documentation

Sofia-SIP Rust bindings tries to mimic almost as possible the API of Sofia-SIP C library. You can start by learning the concepts of Sofia SIP User Agent Library - "nua" - High-Level User Agent Module.

After this intro, please read the tests from Nua module.

Sofia-SIP C docs

Sofia SIP User Agent Library - sofia-sip-ua

Common runtime library: - Sofia SIP User Agent Library - "su" - OS Services and Utilities. - Sofia SIP User Agent Library - "sresolv" - Asynchronous DNS Resolver. - Sofia SIP User Agent Library - "ipt" - Utility Module.

SIP Signaling: - Sofia SIP User Agent Library - "nua" - High-Level User Agent Module. - Sofia SIP User Agent Library - "nea" - SIP Events Module. - Sofia SIP User Agent Library - "iptsec" - Authentication Module. - Sofia SIP User Agent Library - "nta" - SIP Transactions Module. - Sofia SIP User Agent Library - "tport" - Transport Module. - Sofia SIP User Agent Library - "sip" - SIP Parser Module. - Sofia SIP User Agent Library - "msg" - Message Parser Module. - Sofia SIP User Agent Library - "url" - URL Module. - Sofia SIP User Agent Library - "bnf" - String Parser Module.

HTTP subsystem: - Sofia SIP User Agent Library - "nth" - HTTP Transactions Module. - Sofia SIP User Agent Library - "http" - HTTP Parser Module.

SDP processing: - Sofia SIP User Agent Library - "soa" - SDP Offer/Answer Engine Module. - Sofia SIP User Agent Library - "sdp" - SDP Module.

Other: - Sofia SIP User Agent Library - "features" Module. - Sofia SIP User Agent Library - "stun" - STUN Client and Server Module.

Acknowledgements

Authors

License

Before compiling statically, please read this.

Roadmap

NUA is the High-Level User Agent Module of lib-sofia. To learn more about sofia modules, go to reference documentation for libsofia-sip-ua submodules.