message

package
v0.0.0-...-23f20be Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	REGISTER  = Method("REGISTER")
	INVITE    = Method("INVITE")
	ACK       = Method("ACK")
	CANCEL    = Method("CANCEL")
	BYE       = Method("BYE")
	OPTIONS   = Method("OPTIONS")
	SUBSCRIBE = Method("SUBSCRIBE")
	NOTIFY    = Method("NOTIFY")
	REFER     = Method("REFER")
	INFO      = Method("INFO")
)

https://tools.ietf.org/html/rfc3261 7.1 - Method: This specification defines six methods: REGISTER for registering contact information, INVITE, ACK, and CANCEL for setting up sessions, BYE for terminating sessions, and OPTIONS for querying servers about their capabilities. SIP extensions, documented in standards track RFCs, may define additional methods.

View Source
const Version = "SIP/2.0"

Version hold the SIP version string used on Request Lines

Variables

View Source
var (
	//Methods holds the list of All Request Methods
	Methods = []Method{REGISTER, INVITE, ACK, CANCEL, BYE, OPTIONS, SUBSCRIBE, NOTIFY, REFER, INFO}
	//SP means space. This is the separator between the Request Line fields.
	SP = byte(' ')
)
View Source
var (
	SIPScheme     = URIScheme("sip:")
	SIPSScheme    = URIScheme("sips:")
	SIPSchemeStr  = string(SIPScheme)
	SIPSSchemeStr = string(SIPSScheme)
)

Define the URIScheme values

View Source
var (
	ErrInvalidTransport       = errors.New("message.Via: Invalid Transport")
	ErrInvalidViaHeaderFormat = errors.New("message.Via: Invalid Via Header Format")
)

Defining errors

View Source
var (

	//CRLF defines the end of line.
	CRLF = []byte{'\r', '\n'}
)
View Source
var (
	ErrUnknownHeader = errors.New("message.Header: Unknown header")
)

Defining errors

View Source
var Transports = []Transport{UDP, TCP, TLS, SCTP}

Transports holds a list of valid Transports

Functions

func WriteHeader

func WriteHeader(b *bytes.Buffer, h Header)

WriteHeader method writes the HeaderField following the section 7.3.1

func WriteKVPs

func WriteKVPs(b *bytes.Buffer, kvps []KVP, KVPsSep byte, sep byte)

WriteKVPs writes to a byte buffer a list of KVPs

Types

type CSeq

type CSeq struct {
	Seq    uint32
	Method Method
}

CSeq represents the CSeq SIP Header

func ParseCSeq

func ParseCSeq(value string) (*CSeq, error)

ParseCSeq parses a string value to a CSeq instance

func (CSeq) CHeader

func (CSeq) CHeader() string

CHeader returns the compact header tag

func (CSeq) Header

func (CSeq) Header() string

Header returns the header tag

func (CSeq) String

func (c CSeq) String() string

type CallID

type CallID string

CallID represents the Call-ID SIP header

func ParseCallID

func ParseCallID(value string) (*CallID, error)

ParseCallID receives a string and parses it to the CallID type

func (CallID) CHeader

func (CallID) CHeader() string

CHeader returns the compact header tag

func (CallID) Header

func (CallID) Header() string

Header returns the header tag

func (CallID) String

func (c CallID) String() string

String returns the CallID in string format

type Contact

type Contact struct {
	DisplayName string
	SIPURI      SIPURI
	Params      []KVP
}

Contact represents the Contact SIP Header

func (Contact) CHeader

func (Contact) CHeader() string

CHeader returns the compact header tag

func (Contact) Header

func (Contact) Header() string

Header returns the header tag

func (Contact) String

func (c Contact) String() string

type ContentLength

type ContentLength int

ContentLength represents the Content-Length SIP Header

func ParseContentLength

func ParseContentLength(value string) (*ContentLength, error)

ParseContentLength parses a string value to a ContentLength instance and returns as a Header interface

func (ContentLength) CHeader

func (ContentLength) CHeader() string

CHeader returns the compact header tag

func (ContentLength) Header

func (ContentLength) Header() string

Header returns the header tag

func (ContentLength) String

func (cl ContentLength) String() string

type From

type From struct {
	DisplayName string
	SIPURI      SIPURI
	Params      []KVP
}

From represents the From SIP Header

func (From) CHeader

func (From) CHeader() string

CHeader returns the compact header tag

func (From) Header

func (From) Header() string

Header returns the header tag

func (From) String

func (c From) String() string
type Header interface {
	Header() string
	CHeader() string // Tag in the compact form
	String() string
}

Header is a type used by the SIP Headers. []byte is a convenient way to parse and write.

func NewContact

func NewContact(displayName string, sipuri *SIPURI, params []KVP) (Header, error)

NewContact is a constructor of the Contact Header

func NewFrom

func NewFrom(displayName string, sipuri *SIPURI, params []KVP) (Header, error)

NewFrom is a constructor of the From Header

func NewTo

func NewTo(displayName string, sipuri *SIPURI, params []KVP) (Header, error)

NewTo is a constructor of the To Header

func ParseContact

func ParseContact(value string, new NewContactHeaderFunc) (Header, error)

ParseContact parses a string value to a Contact instance and returns as a Header interface

func ParseHeader

func ParseHeader(b []byte) (Header, error)

ParseHeader parses a byte slice value to a Header instance

func ParseHeaders

func ParseHeaders(line string) ([]Header, error)

ParseHeaders follows the section 7.3.1 Header Field Format It receives a string with one or more headers

type KVP

type KVP struct {
	Key   string
	Value string
}

KVP is a key value pair type used to define ordered Params in KPV slices.

func ParseKVP

func ParseKVP(buf []byte, sep byte) (*KVP, bool)

ParseKVP parses a byte slice to a KVP instance The second parameter sep is the separator between the key and the value

func ParseKVPs

func ParseKVPs(value, KVPsSep string, sep byte) []KVP

ParseKVPs parses a string with KVPs separated by a token and returns a slice of KVPs

Examples:
value: "param1=1234;param2=5678" KVPsSep: ";"  KVPSep: '='
value: "param1=abcd&param2=efgh" KVPsSep: "&"  KVPSep: '='

func (KVP) Write

func (p KVP) Write(b *bytes.Buffer, sep byte)

type MaxForwards

type MaxForwards uint8

MaxForwards represents the Max-Forwards SIP Header

func ParseMaxForwards

func ParseMaxForwards(value string) (*MaxForwards, error)

ParseMaxForwards a string value to a MaxForwards instance

func (MaxForwards) CHeader

func (MaxForwards) CHeader() string

CHeader returns the compact header tag

func (MaxForwards) Header

func (MaxForwards) Header() string

Header returns the header tag

func (MaxForwards) String

func (f MaxForwards) String() string

type Method

type Method = string

Method https://tools.ietf.org/html/rfc3261 The method is the primary function that a REQUEST is meant to invoke on a server. The method is carried in the request message itself. Example methods are INVITE and BYE.

type NewContactHeaderFunc

type NewContactHeaderFunc func(displayName string, SIPURI *SIPURI, params []KVP) (Header, error)

NewContactHeaderFunc is a function type to be implemented by Constructors of Contact style types like From, To and Contact

type Request

type Request struct {
	Method     Method
	RequestURI string //RFC 3261 Section 8.1.1.1
	Headers    []Header
	Body       []byte
}

Request type holds the data that identifies a request from a User Agent Client(UAC). The mandatory headers are members of this type. The remaining headers and the body can be extracted from the RawContent attribute through helper methods. This approach avoids unnecessary parsing.

func ParseRequest

func ParseRequest(rawData string) (*Request, error)

ParseRequest parses a string to a Request instance

func (Request) String

func (r Request) String() string

func (Request) Write

func (r Request) Write(w io.Writer) error

type Response

type Response struct {
	StatusCode   string
	ReasonPhrase string
	Headers      []Header
	Body         []byte
}

Response type holds the data from a User Agent Server(UAS) in response of a Request.

func ParseResponse

func ParseResponse(rawData string) (*Response, error)

ParseResponse parses a string to a Response instance

func (Response) String

func (r Response) String() string

func (Response) Write

func (r Response) Write(w io.Writer) error

type SIPURI

type SIPURI struct {
	Scheme  *URIScheme
	User    string
	Host    string
	Params  []KVP
	Headers []KVP
}

SIPURI 19.1.1 SIP-URI components sip:user:password@host:port;uri-parameters?headers

func ParseURI

func ParseURI(value string) (*SIPURI, error)

ParseURI parses a string value to a SIPURI instance

func (*SIPURI) FormatedContainsSep

func (s *SIPURI) FormatedContainsSep() bool

FormatedContainsSep checks if the formated version includes separators. This function is primarily used by the Contact format.

func (*SIPURI) IsValid

func (s *SIPURI) IsValid() error

IsValid check if the mandatory fields are present

func (SIPURI) String

func (s SIPURI) String() string

func (*SIPURI) Write

func (s *SIPURI) Write(b *bytes.Buffer) error

Write method writes the SIPURI formated to a byte Buffer

type To

type To struct {
	DisplayName string
	SIPURI      SIPURI
	Params      []KVP
}

To represents the To SIP Header

func (To) CHeader

func (To) CHeader() string

CHeader returns the compact header tag

func (To) Header

func (To) Header() string

Header returns the header tag

func (To) String

func (c To) String() string

type Transport

type Transport = string

Transport represents the transport protocol

const (
	UDP  Transport = "UDP"
	TCP  Transport = "TCP"
	TLS  Transport = "TLS"
	SCTP Transport = "SCTP"
)

Transport constants definitions

type URIScheme

type URIScheme []byte

URIScheme represents a Scheme type in the SIPURI specification - SIP: or SIPS:

type Via

type Via struct {
	Transport Transport
	Host      string
	Params    []KVP
}

Via represents the Via SIP header

func ParseVia

func ParseVia(value string) (*Via, error)

ParseVia parses a string value to the Via type

func (Via) CHeader

func (Via) CHeader() string

func (Via) Header

func (Via) Header() string

func (Via) String

func (v Via) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL