Crate libsip

Source
Expand description

libsip has three basic components a parser and managers.

Managers are utility struct’s meant to ease one specifc asspect of the sip protocol, the only manager currently implemented is for endpoint registration.

§Parsing

libsip exposes many parsing function though only one parse_message is needed.

extern crate libsip;
extern crate nom;

use libsip::parse_message;
use nom::error::VerboseError;

let packet = "SIP/2.0 200 OK\r\n\r\n";
let output = libsip::parse_message::<VerboseError<&[u8]>>(packet.as_ref()).unwrap();

§Creating Messages

This crate provides 2 abstraction’s to aid in building sip messages. The ResponseGenerator is used to create sip response’s and the RequestGenerator is used to generate sip requests.

   extern crate libsip;
   extern crate nom;

   use nom::error::VerboseError;
   use libsip::ResponseGenerator;
   use libsip::RequestGenerator;
   use libsip::Method;
   use libsip::uri::parse_uri;

   let _res = ResponseGenerator::new()
                       .code(200)
                       .build()
                       .unwrap();

   let uri = parse_uri::<VerboseError<&[u8]>>("sip:1@0.0.0.0:5060;transport=UDP".as_ref()).unwrap().1;
   let _req = RequestGenerator::new()
                       .method(Method::Invite)
                       .uri(uri)
                       .build()
                       .unwrap();

§Registration

The registration manager is used to generate REGISTER requests. Once that is sent to the server you must wait for the Challange response pass it to the set_challenge method of the RegistrationManager. reqpeatedly calling the get_request method will cause the c_nonce counter to be incremented and a new hash computed.

Re-exports§

pub use crate::core::parse_message;
pub use crate::core::parse_request;
pub use crate::core::parse_response;
pub use crate::core::parse_version;
pub use crate::core::Method;
pub use crate::core::RegisterRequestExt;
pub use crate::core::SipMessage;
pub use crate::core::SipMessageExt;
pub use crate::core::Transport;
pub use crate::core::Version;
pub use crate::headers::parse_header;
pub use crate::headers::via::ViaHeader;
pub use crate::headers::AuthContext;
pub use crate::headers::AuthHeader;
pub use crate::headers::AuthSchema;
pub use crate::headers::ContentType;
pub use crate::headers::Header;
pub use crate::headers::Headers;
pub use crate::headers::Language;
pub use crate::headers::NamedHeader;
pub use crate::headers::SubscriptionState;
pub use crate::uri::parse_uri;
pub use crate::uri::Domain;
pub use crate::uri::Uri;
pub use crate::uri::UriAuth;
pub use crate::uri::UriParam;
pub use crate::uri::UriSchema;

Modules§

core
headers
parse
uri

Macros§

domain
Generate a URI domain from an domain name.
ip_domain
Generate a URI domain from an ip address.
named_header
Generate NamedHeader from a uri;
uri_auth
Generate a URI authentication from credentials.

Structs§

HeaderWriteConfig
This struct is used in the client module when creating sip messages it is used to specify some common values for the generated sip headers.
InviteHelper
Structure to ease getting data from a Sip INVITE request. Also is used to generate the appropiate Ringing and Ok responses.
MessageHelper
Structure to ease getting data from a Sip Message request.
MessageWriter
Structure to help when sending Sip messages. Handles the message CSeq, Call-Id and User-Agent headers.
RegistrationManager
Handle’s the SIP registration process. This structure is designed to handle the authentication process from a SoftPhone’s point of view.
RequestGenerator
Sip Request Generator. When build is called the struct is consumed and produces a SipMessage::Request variant. Calling the method & uri methods before the build method is required.
ResponseGenerator
Sip Response Generator. When build is called the struct is consumed and produces a SipMessage::Response variant. Calling the code method before the build method is required.
SoftPhone
Simple SIP client for implementing softphones. Currently the only thing implemented is registration and sending text messages. The only other feature planned is an interface for sending & receiving calls.