[][src]Crate libsip

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::headers::Header;
pub use crate::headers::Headers;
pub use crate::headers::AuthHeader;
pub use crate::headers::AuthContext;
pub use crate::headers::parse_header;
pub use crate::headers::AuthSchema;
pub use crate::headers::via::ViaHeader;
pub use crate::uri::Domain;
pub use crate::uri::UriParam;
pub use crate::uri::Uri;
pub use crate::uri::UriAuth;
pub use crate::uri::UriSchema;
pub use crate::uri::parse_uri;

Modules

headers
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.

NamedHeader

Header Value for Named Headers, e.g. From, To, Contact

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.

Version

SIP Protocol version struct. default: 2.0

Enums

ContentType

Sip protocol Content-Type value.

Language

Sip Protocol languages.

Method

SIP protocol methods.

SipMessage

Sip Protocol Message.

Transport

SIP protocol transport.

Functions

parse_message

This is the main parsing function for libsip.

parse_request

Parse a SIP message assuming it is a SIP request.

parse_response

Parse a SIP message assuming it is a SIP response.

parse_version

Parse the SIP protocol version.