[][src]Crate sipmsg

Introduction

Library for parsing/editing/constructing SIP requests and responses.

This is the very first version where only simple parsing is support.

Example


use sipmsg::*;

let invite_msg_buf = "\
INVITE sip:bob@biloxi.com;user=phone?to=alice%40atlanta.com&priority=urgent SIP/2.0\r\n\
Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKkjshdyff\r\n\
Via: SIP/2.0/UDP 192.168.1.111\r\n\
To: Bob <sip:bob@biloxi.com>\r\n\
From: Alice <sip:alice@atlanta.com>;tag=88sja8x\r\n\
Max-Forwards: 70\r\n\
Call-ID: 987asjd97y7atg\r\n\
CSeq: 986759 INVITE\r\n\r\nbody_stuff"
.as_bytes();

// First parameter not realized yet.
// It should consist be residue if Content-Length is less then actual body length.
let (_, request) = SipRequest::parse(invite_msg_buf).unwrap();
assert_eq!(request.rl.method, SipRequestMethod::INVITE);
assert_eq!(request.rl.sip_version, SipVersion(2, 0));

// RURI
assert_eq!(request.rl.uri.scheme, SipRequestUriScheme::SIP);
assert_eq!(request.rl.uri.user_info().unwrap().value, "bob");
assert_eq!(request.rl.uri.hostport.host, "biloxi.com");
assert_eq!(request.rl.uri.params().unwrap().get(&"user"), Some(&"phone"));
assert_eq!(request.rl.uri.headers().unwrap().get(&"to"), Some(&"alice%40atlanta.com"));
assert_eq!(request.rl.uri.headers().unwrap().get(&"priority"), Some(&"urgent"));

// Via Header
let via_headers = request.headers.get("via").unwrap(); // case insensitive
assert_eq!(via_headers[1].value, "SIP/2.0/UDP pc33.atlanta.com");
assert_eq!(via_headers[1].params().unwrap().get(&"branch"),  Some(&"z9hG4bKkjshdyff"));
assert_eq!(via_headers[0].value, "SIP/2.0/UDP 192.168.1.111");
 
assert_eq!(
    via_headers[1].params().unwrap().get(&"branch"),
    Some(&"z9hG4bKkjshdyff")
);

assert_eq!(
    via_headers[1].params().unwrap().get(&"notExistParam"),
    None
);

// Body
assert_eq!(request.body.unwrap(), "body_stuff".as_bytes());

Modules

bnfcore

Structs

SipHeader

rfc3261 section-7.3

SipHeaders
SipRequest

rfc3261 section-7.1

SipRequestLine

Ex: INVITE sip:user@example.com SIP/2.0 The Request line and u8 buffer shoud have the same life time

SipResponse
SipResponseStatusLine

Ex: SIP/2.0 401 Unauthorized

SipUri

Its general form, in the case of a SIP URI, is: sip:user:password@host:port;uri-parameters?headers

SipVersion

SIP-Version ex. SIP/2.0 -> SipVersion(2, 0)

Enums

SipMessageType
SipRequestMethod
SipRequestUriScheme
SipResponseStatusCode

Traits

SipMessageParser

Functions

get_sip_message_type

Fast determinates message type and minimal validate for further transmission to suitable parser. Does not validate full first line, just first 3 bytes.