Documentation
¶
Index ¶
- Constants
- Variables
- func ASCIIToLower(s string) string
- func ASCIIToLowerInPlace(s []byte)
- func CopyHeaders(name string, from, to Message)
- func DefaultHeadersParser() map[string]HeaderParser
- func DefaultPort(transport string) int
- func GenerateBranch() string
- func GenerateBranchN(n int) string
- func GenerateTagN(n int) string
- func HeaderToLower(s string) string
- func MakeDialogID(callID, innerID, externalID string) string
- func MakeDialogIDFromMessage(msg Message) (string, error)
- func MakeDialogIDFromRequest(msg *Request) (string, error)
- func MakeDialogIDFromResponse(msg *Response) (string, error)
- func MessageShortString(msg Message) string
- func NonceWrite(buf []byte)
- func ParseAddr(addr string) (host string, port int, err error)
- func ParseAddressValue(addressText string, uri *Uri, headerParams HeaderParams) (displayName string, err error)
- func ParseUri(uriStr string, uri *Uri) (err error)
- func RandString(n int) string
- func RandStringBytesMask(sb *strings.Builder, n int) string
- func ResolveSelfIP() (net.IP, error)
- func SplitByWhitespace(text string) []string
- func UnmarshalParams(s string, seperator rune, ending rune, p HeaderParams) (n int, err error)
- func UriIsSIP(s string) bool
- func UriIsSIPS(s string) bool
- type CSeqHeader
- type CallIDHeader
- type ClientTransaction
- type ContactHeader
- type ContentLengthHeader
- type ContentTypeHeader
- type CopyHeader
- type ExpiresHeader
- type FromHeader
- type Header
- type HeaderKV
- type HeaderParams
- func (hp HeaderParams) Add(key string, val string) Params
- func (hp HeaderParams) Clone() Params
- func (hp HeaderParams) Equals(other interface{}) bool
- func (hp HeaderParams) Get(key string) (string, bool)
- func (hp HeaderParams) Has(key string) bool
- func (hp HeaderParams) Items() map[string]string
- func (hp HeaderParams) Keys() []string
- func (hp HeaderParams) Length() int
- func (hp HeaderParams) Remove(key string) Params
- func (hp HeaderParams) String() string
- func (hp HeaderParams) ToString(sep uint8) string
- func (hp HeaderParams) ToStringWrite(sep uint8, buffer io.StringWriter)
- type HeaderParser
- type IPAddr
- type MaxForwardsHeader
- type Message
- type MessageData
- func (hs *MessageData) AppendHeader(header Header)
- func (hs *MessageData) AppendHeaderAfter(header Header, name string)
- func (msg *MessageData) Body() []byte
- func (hs *MessageData) CSeq() (*CSeqHeader, bool)
- func (hs *MessageData) CallID() (*CallIDHeader, bool)
- func (hs *MessageData) CloneHeaders() []Header
- func (hs *MessageData) Contact() (*ContactHeader, bool)
- func (hs *MessageData) ContentLength() (*ContentLengthHeader, bool)
- func (hs *MessageData) ContentType() (*ContentTypeHeader, bool)
- func (msg *MessageData) Destination() string
- func (hs *MessageData) From() (*FromHeader, bool)
- func (hs *MessageData) GetHeader(name string) Header
- func (hs *MessageData) GetHeaders(name string) []Header
- func (hs *MessageData) Headers() []Header
- func (hs *MessageData) MaxForwards() (*MaxForwardsHeader, bool)
- func (hs *MessageData) PrependHeader(headers ...Header)
- func (hs *MessageData) RecordRoute() (*RecordRouteHeader, bool)
- func (hs *MessageData) RemoveHeader(name string) (removed bool)
- func (hs *MessageData) RemoveHeaderOn(name string, f func(h Header) bool) (removed bool)
- func (hs *MessageData) ReplaceHeader(header Header)
- func (hs *MessageData) Route() (*RouteHeader, bool)
- func (msg *MessageData) SetBody(body []byte)
- func (msg *MessageData) SetDestination(dest string)
- func (msg *MessageData) SetSource(src string)
- func (msg *MessageData) SetTransport(tp string)
- func (msg *MessageData) Source() string
- func (hs *MessageData) String() string
- func (hs *MessageData) StringWrite(buffer io.StringWriter)
- func (hs *MessageData) To() (*ToHeader, bool)
- func (msg *MessageData) Transport() string
- func (hs *MessageData) Via() (*ViaHeader, bool)
- type MessageHandler
- type Params
- type Parser
- type ParserOption
- type ParserStream
- type RecordRouteHeader
- func (h *RecordRouteHeader) Clone() *RecordRouteHeader
- func (h *RecordRouteHeader) Name() string
- func (h *RecordRouteHeader) String() string
- func (h *RecordRouteHeader) StringWrite(buffer io.StringWriter)
- func (h *RecordRouteHeader) Value() string
- func (h *RecordRouteHeader) ValueStringWrite(buffer io.StringWriter)
- type Request
- func CopyRequest(req *Request) *Request
- func NewAckRequest(inviteRequest *Request, inviteResponse *Response, body []byte) *Request
- func NewByeRequestUAC(inviteRequest *Request, inviteResponse *Response, body []byte) *Request
- func NewCancelRequest(requestForCancel *Request) *Request
- func NewRequest(method RequestMethod, recipient *Uri) *Request
- func (hs *Request) AppendHeader(header Header)
- func (hs *Request) AppendHeaderAfter(header Header, name string)
- func (hs *Request) CSeq() (*CSeqHeader, bool)
- func (hs *Request) CallID() (*CallIDHeader, bool)
- func (req *Request) Clone() *Request
- func (hs *Request) CloneHeaders() []Header
- func (hs *Request) Contact() (*ContactHeader, bool)
- func (hs *Request) ContentLength() (*ContentLengthHeader, bool)
- func (hs *Request) ContentType() (*ContentTypeHeader, bool)
- func (req *Request) Destination() string
- func (hs *Request) From() (*FromHeader, bool)
- func (hs *Request) GetHeader(name string) Header
- func (hs *Request) GetHeaders(name string) []Header
- func (hs *Request) Headers() []Header
- func (req *Request) IsAck() bool
- func (req *Request) IsCancel() bool
- func (req *Request) IsInvite() bool
- func (hs *Request) MaxForwards() (*MaxForwardsHeader, bool)
- func (hs *Request) PrependHeader(headers ...Header)
- func (hs *Request) RecordRoute() (*RecordRouteHeader, bool)
- func (hs *Request) RemoveHeader(name string) (removed bool)
- func (hs *Request) RemoveHeaderOn(name string, f func(h Header) bool) (removed bool)
- func (hs *Request) ReplaceHeader(header Header)
- func (hs *Request) Route() (*RouteHeader, bool)
- func (req *Request) Short() string
- func (req *Request) Source() string
- func (req *Request) StartLine() string
- func (req *Request) StartLineWrite(buffer io.StringWriter)
- func (req *Request) String() string
- func (req *Request) StringWrite(buffer io.StringWriter)
- func (hs *Request) To() (*ToHeader, bool)
- func (req *Request) Transport() string
- func (hs *Request) Via() (*ViaHeader, bool)
- type RequestMethod
- type Response
- func (hs *Response) AppendHeader(header Header)
- func (hs *Response) AppendHeaderAfter(header Header, name string)
- func (hs *Response) CSeq() (*CSeqHeader, bool)
- func (hs *Response) CallID() (*CallIDHeader, bool)
- func (res *Response) Clone() *Response
- func (hs *Response) CloneHeaders() []Header
- func (hs *Response) Contact() (*ContactHeader, bool)
- func (hs *Response) ContentLength() (*ContentLengthHeader, bool)
- func (hs *Response) ContentType() (*ContentTypeHeader, bool)
- func (res *Response) Destination() string
- func (hs *Response) From() (*FromHeader, bool)
- func (hs *Response) GetHeader(name string) Header
- func (hs *Response) GetHeaders(name string) []Header
- func (hs *Response) Headers() []Header
- func (res *Response) IsAck() bool
- func (res *Response) IsCancel() bool
- func (res *Response) IsClientError() bool
- func (res *Response) IsGlobalError() bool
- func (res *Response) IsProvisional() bool
- func (res *Response) IsRedirection() bool
- func (res *Response) IsServerError() bool
- func (res *Response) IsSuccess() bool
- func (hs *Response) MaxForwards() (*MaxForwardsHeader, bool)
- func (hs *Response) PrependHeader(headers ...Header)
- func (hs *Response) RecordRoute() (*RecordRouteHeader, bool)
- func (hs *Response) RemoveHeader(name string) (removed bool)
- func (hs *Response) RemoveHeaderOn(name string, f func(h Header) bool) (removed bool)
- func (hs *Response) ReplaceHeader(header Header)
- func (hs *Response) Route() (*RouteHeader, bool)
- func (res *Response) Short() string
- func (res *Response) StartLine() string
- func (res *Response) StartLineWrite(buffer io.StringWriter)
- func (res *Response) String() string
- func (res *Response) StringWrite(buffer io.StringWriter)
- func (hs *Response) To() (*ToHeader, bool)
- func (res *Response) Transport() string
- func (hs *Response) Via() (*ViaHeader, bool)
- type RouteHeader
- type ServerTransaction
- type StatusCode
- type ToHeader
- type Transaction
- type Transport
- type Uri
- type ViaHeader
Constants ¶
const ( // Dialog received 200 response DialogStateEstablished = iota // Dialog received ACK DialogStateConfirmed // Dialog received BYE DialogStateEnded )
Variables ¶
var ( ErrParseLineNoCRLF = errors.New("line has no CRLF") ErrParseInvalidMessage = errors.New("invalid SIP message") // Stream parse errors ErrParseSipPartial = errors.New("SIP partial data") ErrParseReadBodyIncomplete = errors.New("reading body incomplete") ErrParseMoreMessages = errors.New("Stream has more message") )
Functions ¶
func ASCIIToLower ¶
ASCIIToLower is faster than go version. It avoids one more loop
func ASCIIToLowerInPlace ¶
func ASCIIToLowerInPlace(s []byte)
func CopyHeaders ¶
Copy all headers of one type from one message to another. Appending to any headers that were already there.
func DefaultHeadersParser ¶ added in v0.15.0
func DefaultHeadersParser() map[string]HeaderParser
DefaultHeadersParser returns minimal version header parser. It can be extended or overwritten. Removing some defaults can break SIP functionality
NOTE this API call may change
func DefaultPort ¶
DefaultPort returns transport default port by network.
func GenerateBranchN ¶ added in v0.7.2
GenerateBranchN returns random unique branch ID in format MagicCookie.<n chars>
func GenerateTagN ¶ added in v0.11.0
func MakeDialogID ¶
func MakeDialogIDFromMessage ¶
MakeDialogIDFromMessage creates dialog ID of message. returns error if callid or to tag or from tag does not exists Deprecated! Will be removed
func MakeDialogIDFromRequest ¶ added in v0.13.0
func MakeDialogIDFromResponse ¶ added in v0.13.0
func MessageShortString ¶ added in v0.8.0
MessageShortString dumps short version of msg. Used only for logging
func NonceWrite ¶ added in v0.7.2
func NonceWrite(buf []byte)
func ParseAddressValue ¶ added in v0.15.0
func ParseAddressValue(addressText string, uri *Uri, headerParams HeaderParams) (displayName string, err error)
ParseAddressValue parses an address - such as from a From, To, or Contact header. It returns: See RFC 3261 section 20.10 for details on parsing an address. Note that this method will not accept a comma-separated list of addresses.
func ParseUri ¶ added in v0.15.0
ParseUri converts a string representation of a URI into a Uri object. Following https://datatracker.ietf.org/doc/html/rfc3261#section-19.1.1 sip:user:password@host:port;uri-parameters?headers
func RandStringBytesMask ¶ added in v0.7.2
https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go
func ResolveSelfIP ¶
Forked from github.com/StefanKopieczek/gossip by @StefanKopieczek
func SplitByWhitespace ¶
Splits the given string into sections, separated by one or more characters from c_ABNF_WS.
func UnmarshalParams ¶ added in v0.15.0
Types ¶
type CSeqHeader ¶
type CSeqHeader struct {
SeqNo uint32
MethodName RequestMethod
}
CSeq is CSeq header
func (*CSeqHeader) Name ¶
func (h *CSeqHeader) Name() string
func (*CSeqHeader) String ¶
func (h *CSeqHeader) String() string
func (*CSeqHeader) StringWrite ¶
func (h *CSeqHeader) StringWrite(buffer io.StringWriter)
func (*CSeqHeader) Value ¶
func (h *CSeqHeader) Value() string
func (*CSeqHeader) ValueStringWrite ¶
func (h *CSeqHeader) ValueStringWrite(buffer io.StringWriter)
type CallIDHeader ¶
type CallIDHeader string
CallIDHeader is a Call-ID header presentation
func (*CallIDHeader) Name ¶
func (h *CallIDHeader) Name() string
func (*CallIDHeader) String ¶
func (h *CallIDHeader) String() string
func (*CallIDHeader) StringWrite ¶
func (h *CallIDHeader) StringWrite(buffer io.StringWriter)
func (*CallIDHeader) Value ¶
func (h *CallIDHeader) Value() string
type ClientTransaction ¶
type ClientTransaction interface {
Transaction
// Responses returns channel with all responses for transaction
Responses() <-chan *Response
// Cancel sends cancel request
Cancel() error
}
type ContactHeader ¶
type ContactHeader struct {
// The display name from the header, may be omitted.
DisplayName string
Address Uri
// Any parameters present in the header.
Params HeaderParams
}
ContactHeader is Contact header representation
func (*ContactHeader) Clone ¶
func (h *ContactHeader) Clone() *ContactHeader
func (*ContactHeader) Name ¶
func (h *ContactHeader) Name() string
func (*ContactHeader) String ¶
func (h *ContactHeader) String() string
func (*ContactHeader) StringWrite ¶
func (h *ContactHeader) StringWrite(buffer io.StringWriter)
func (*ContactHeader) Value ¶
func (h *ContactHeader) Value() string
type ContentLengthHeader ¶
type ContentLengthHeader uint32
ContentLengthHeader is Content-Length header representation
func (*ContentLengthHeader) Name ¶
func (h *ContentLengthHeader) Name() string
func (ContentLengthHeader) String ¶
func (h ContentLengthHeader) String() string
func (ContentLengthHeader) StringWrite ¶
func (h ContentLengthHeader) StringWrite(buffer io.StringWriter)
func (ContentLengthHeader) Value ¶
func (h ContentLengthHeader) Value() string
type ContentTypeHeader ¶
type ContentTypeHeader string
ContentTypeHeader is Content-Type header representation.
func (*ContentTypeHeader) Name ¶
func (h *ContentTypeHeader) Name() string
func (*ContentTypeHeader) String ¶
func (h *ContentTypeHeader) String() string
func (*ContentTypeHeader) StringWrite ¶
func (h *ContentTypeHeader) StringWrite(buffer io.StringWriter)
func (ContentTypeHeader) Value ¶
func (h ContentTypeHeader) Value() string
type CopyHeader ¶
type CopyHeader interface {
// contains filtered or unexported methods
}
CopyHeader is internal interface for cloning headers. Maybe it will be full exposed later
type ExpiresHeader ¶
type ExpiresHeader uint32
ExpiresHeader is Expires header representation
func (*ExpiresHeader) Name ¶
func (h *ExpiresHeader) Name() string
func (*ExpiresHeader) String ¶
func (h *ExpiresHeader) String() string
func (*ExpiresHeader) StringWrite ¶
func (h *ExpiresHeader) StringWrite(buffer io.StringWriter)
func (ExpiresHeader) Value ¶
func (h ExpiresHeader) Value() string
type FromHeader ¶
type FromHeader struct {
// The display name from the header, may be omitted.
DisplayName string
Address Uri
// Any parameters present in the header.
Params HeaderParams
}
func (*FromHeader) Name ¶
func (h *FromHeader) Name() string
func (*FromHeader) Next ¶
func (header *FromHeader) Next() Header
func (*FromHeader) String ¶
func (h *FromHeader) String() string
func (*FromHeader) StringWrite ¶
func (h *FromHeader) StringWrite(buffer io.StringWriter)
func (*FromHeader) Value ¶
func (h *FromHeader) Value() string
func (*FromHeader) ValueStringWrite ¶
func (h *FromHeader) ValueStringWrite(buffer io.StringWriter)
type Header ¶
type Header interface {
// Name returns header name.
Name() string
Value() string
String() string
// StringWrite is better way to reuse single buffer
StringWrite(w io.StringWriter)
// contains filtered or unexported methods
}
Header is a single SIP header.
func HeaderClone ¶
HeaderClone is generic function for cloning header
type HeaderParams ¶
HeaderParams are key value params. They do not provide order by default due to performance reasons
func (HeaderParams) Add ¶
func (hp HeaderParams) Add(key string, val string) Params
Add will add new key:val. If key exists it will be overwriten
func (HeaderParams) Clone ¶
func (hp HeaderParams) Clone() Params
Clone returns underneath map copied
func (HeaderParams) Equals ¶
func (hp HeaderParams) Equals(other interface{}) bool
Equals check if two maps of parameters are equal in the sense of having the same keys with the same values. This does not rely on any ordering of the keys of the map in memory.
func (HeaderParams) Get ¶
func (hp HeaderParams) Get(key string) (string, bool)
Get returns existing key
func (HeaderParams) Items ¶
func (hp HeaderParams) Items() map[string]string
Items returns the entire parameter map.
func (HeaderParams) Keys ¶
func (hp HeaderParams) Keys() []string
Keys return a slice of keys, in order.
func (HeaderParams) Remove ¶
func (hp HeaderParams) Remove(key string) Params
Remove removes param with exact key
func (HeaderParams) String ¶
func (hp HeaderParams) String() string
String returns params joined with '&' char.
func (HeaderParams) ToString ¶
func (hp HeaderParams) ToString(sep uint8) string
ToString renders params to a string. Note that this does not escape special characters, this should already have been done before calling this method.
func (HeaderParams) ToStringWrite ¶
func (hp HeaderParams) ToStringWrite(sep uint8, buffer io.StringWriter)
ToStringWrite is same as ToString but it stores to defined buffer instead returning string
type HeaderParser ¶ added in v0.15.0
A HeaderParser is any function that turns raw header data into one or more Header objects.
type MaxForwardsHeader ¶
type MaxForwardsHeader uint32
MaxForwardsHeader is Max-Forwards header representation
func (*MaxForwardsHeader) Dec ¶ added in v0.9.0
func (h *MaxForwardsHeader) Dec()
func (*MaxForwardsHeader) Name ¶
func (h *MaxForwardsHeader) Name() string
func (*MaxForwardsHeader) String ¶
func (h *MaxForwardsHeader) String() string
func (*MaxForwardsHeader) StringWrite ¶
func (h *MaxForwardsHeader) StringWrite(buffer io.StringWriter)
func (MaxForwardsHeader) Val ¶ added in v0.9.0
func (h MaxForwardsHeader) Val() uint32
func (*MaxForwardsHeader) Value ¶
func (h *MaxForwardsHeader) Value() string
type Message ¶
type Message interface {
// String returns string representation of SIP message in RFC 3261 form.
String() string
// String write is same as String but lets you to provide writter and reduce allocations
StringWrite(io.StringWriter)
// GetHeaders returns slice of headers of the given type.
GetHeaders(name string) []Header
// PrependHeader prepends header to message.
PrependHeader(header ...Header)
// AppendHeader appends header to message.
AppendHeader(header Header)
// CallID returns 'Call-ID' header.
CallID() (*CallIDHeader, bool)
// Via returns the top 'Via' header field.
Via() (*ViaHeader, bool)
// From returns 'From' header field.
From() (*FromHeader, bool)
// To returns 'To' header field.
To() (*ToHeader, bool)
// CSeq returns 'CSeq' header field.
CSeq() (*CSeqHeader, bool)
// Body returns message body.
Body() []byte
// SetBody sets message body.
SetBody(body []byte)
Transport() string
SetTransport(tp string)
Source() string
SetSource(src string)
Destination() string
SetDestination(dest string)
}
func ParseMessage ¶ added in v0.15.0
type MessageData ¶
type MessageData struct {
// Set to 2.0 version by default
SipVersion string
// contains filtered or unexported fields
}
func (*MessageData) AppendHeader ¶
func (hs *MessageData) AppendHeader(header Header)
AppendHeader adds header at end of header list
func (*MessageData) AppendHeaderAfter ¶
AppendHeaderAfter adds header after specified header. In case header does not exist normal AppendHeader is called Use it only if you need it
func (*MessageData) Body ¶
func (msg *MessageData) Body() []byte
func (*MessageData) CSeq ¶
func (hs *MessageData) CSeq() (*CSeqHeader, bool)
func (*MessageData) CallID ¶
func (hs *MessageData) CallID() (*CallIDHeader, bool)
func (*MessageData) CloneHeaders ¶
func (hs *MessageData) CloneHeaders() []Header
CloneHeaders returns all cloned headers in slice.
func (*MessageData) Contact ¶
func (hs *MessageData) Contact() (*ContactHeader, bool)
func (*MessageData) ContentLength ¶
func (hs *MessageData) ContentLength() (*ContentLengthHeader, bool)
func (*MessageData) ContentType ¶
func (hs *MessageData) ContentType() (*ContentTypeHeader, bool)
func (*MessageData) Destination ¶
func (msg *MessageData) Destination() string
func (*MessageData) From ¶
func (hs *MessageData) From() (*FromHeader, bool)
func (*MessageData) GetHeader ¶
GetHeader returns Header if exists, otherwise nil is returned Use lower case to avoid allocs Headers are pointers, always Clone them for change
func (*MessageData) GetHeaders ¶
GetHeaders returns list of headers with same name Use lower case to avoid allocs Headers are pointers, always Clone them for change
func (*MessageData) MaxForwards ¶ added in v0.7.2
func (hs *MessageData) MaxForwards() (*MaxForwardsHeader, bool)
func (*MessageData) PrependHeader ¶
func (hs *MessageData) PrependHeader(headers ...Header)
PrependHeader adds header to the front of header list using as list reduces need of realloc underneath array
func (*MessageData) RecordRoute ¶
func (hs *MessageData) RecordRoute() (*RecordRouteHeader, bool)
func (*MessageData) RemoveHeader ¶
RemoveHeader removes header by name
func (*MessageData) RemoveHeaderOn ¶ added in v0.7.0
RemoveHeaderOn before removes header with name, yields (calls func) once it gets found
func (*MessageData) ReplaceHeader ¶
func (hs *MessageData) ReplaceHeader(header Header)
ReplaceHeader replaces first header with same name
func (*MessageData) Route ¶
func (hs *MessageData) Route() (*RouteHeader, bool)
func (*MessageData) SetBody ¶
func (msg *MessageData) SetBody(body []byte)
SetBody sets message body, calculates it length and add 'Content-Length' header.
func (*MessageData) SetDestination ¶
func (msg *MessageData) SetDestination(dest string)
func (*MessageData) SetSource ¶
func (msg *MessageData) SetSource(src string)
func (*MessageData) SetTransport ¶
func (msg *MessageData) SetTransport(tp string)
func (*MessageData) Source ¶
func (msg *MessageData) Source() string
func (*MessageData) StringWrite ¶
func (hs *MessageData) StringWrite(buffer io.StringWriter)
func (*MessageData) Transport ¶
func (msg *MessageData) Transport() string
type MessageHandler ¶
type MessageHandler func(msg Message)
type Params ¶
type Params interface {
Get(key string) (string, bool)
Add(key string, val string) Params
Remove(key string) Params
Clone() Params
Equals(params interface{}) bool
ToString(sep uint8) string
ToStringWrite(sep uint8, buffer io.StringWriter)
String() string
Length() int
Items() map[string]string
Keys() []string
Has(key string) bool
}
type Parser ¶ added in v0.8.0
type Parser struct {
// contains filtered or unexported fields
}
Parser is implementation of SIPParser It is optimized with faster header parsing
func NewParser ¶ added in v0.15.0
func NewParser(options ...ParserOption) *Parser
Create a new Parser.
func (*Parser) NewSIPStream ¶ added in v0.15.0
func (p *Parser) NewSIPStream() *ParserStream
NewSIPStream implements SIP parsing contructor for IO that stream SIP message It should be created per each stream
type ParserOption ¶ added in v0.15.0
type ParserOption func(p *Parser)
ParserOption are addition option for NewParser. Check WithParser...
func WithHeadersParsers ¶ added in v0.15.0
func WithHeadersParsers(m map[string]HeaderParser) ParserOption
WithHeadersParsers allows customizing parser headers parsers Consider performance when adding custom parser. Add only if it will appear in almost every message
Check DefaultHeadersParser as starting point
func WithParserLogger ¶ added in v0.15.0
func WithParserLogger(logger zerolog.Logger) ParserOption
WithServerLogger allows customizing parser logger
type ParserStream ¶ added in v0.15.0
type ParserStream struct {
// contains filtered or unexported fields
}
func (*ParserStream) ParseSIPStream ¶ added in v0.15.0
func (p *ParserStream) ParseSIPStream(data []byte) (msgs []Message, err error)
ParseSIPStream parsing messages comming in stream It has slight overhead vs parsing full message
type RecordRouteHeader ¶
type RecordRouteHeader struct {
Address Uri
Next *RecordRouteHeader
}
RecordRouteHeader is Record-Route header representation.
func (*RecordRouteHeader) Clone ¶
func (h *RecordRouteHeader) Clone() *RecordRouteHeader
func (*RecordRouteHeader) Name ¶
func (h *RecordRouteHeader) Name() string
func (*RecordRouteHeader) String ¶
func (h *RecordRouteHeader) String() string
func (*RecordRouteHeader) StringWrite ¶
func (h *RecordRouteHeader) StringWrite(buffer io.StringWriter)
func (*RecordRouteHeader) Value ¶
func (h *RecordRouteHeader) Value() string
func (*RecordRouteHeader) ValueStringWrite ¶
func (h *RecordRouteHeader) ValueStringWrite(buffer io.StringWriter)
type Request ¶
type Request struct {
MessageData
Method RequestMethod
Recipient *Uri
}
Request RFC 3261 - 7.1.
func CopyRequest ¶
func NewAckRequest ¶
NewAckRequest creates ACK request for 2xx INVITE https://tools.ietf.org/html/rfc3261#section-13.2.2.4
func NewByeRequestUAC ¶ added in v0.14.0
NewByeRequestUAC creates bye request from established dialog https://datatracker.ietf.org/doc/html/rfc3261#section-15.1.1 TODO UAS
func NewCancelRequest ¶
func NewRequest ¶
func NewRequest(method RequestMethod, recipient *Uri) *Request
NewRequest creates base for building sip Request sipVersion must be SIP/2.0 No headers are added. AppendHeader should be called to add Headers. r.SetBody can be called to set proper ContentLength header
func (*Request) AppendHeader ¶
func (hs *Request) AppendHeader(header Header)
AppendHeader adds header at end of header list
func (*Request) AppendHeaderAfter ¶
AppendHeaderAfter adds header after specified header. In case header does not exist normal AppendHeader is called Use it only if you need it
func (*Request) CSeq ¶
func (hs *Request) CSeq() (*CSeqHeader, bool)
func (*Request) CallID ¶
func (hs *Request) CallID() (*CallIDHeader, bool)
func (*Request) CloneHeaders ¶
func (hs *Request) CloneHeaders() []Header
CloneHeaders returns all cloned headers in slice.
func (*Request) Contact ¶
func (hs *Request) Contact() (*ContactHeader, bool)
func (*Request) ContentLength ¶
func (hs *Request) ContentLength() (*ContentLengthHeader, bool)
func (*Request) ContentType ¶
func (hs *Request) ContentType() (*ContentTypeHeader, bool)
func (*Request) Destination ¶
func (*Request) From ¶
func (hs *Request) From() (*FromHeader, bool)
func (*Request) GetHeader ¶
GetHeader returns Header if exists, otherwise nil is returned Use lower case to avoid allocs Headers are pointers, always Clone them for change
func (*Request) GetHeaders ¶
GetHeaders returns list of headers with same name Use lower case to avoid allocs Headers are pointers, always Clone them for change
func (*Request) MaxForwards ¶ added in v0.7.2
func (hs *Request) MaxForwards() (*MaxForwardsHeader, bool)
func (*Request) PrependHeader ¶
func (hs *Request) PrependHeader(headers ...Header)
PrependHeader adds header to the front of header list using as list reduces need of realloc underneath array
func (*Request) RecordRoute ¶
func (hs *Request) RecordRoute() (*RecordRouteHeader, bool)
func (*Request) RemoveHeader ¶
RemoveHeader removes header by name
func (*Request) RemoveHeaderOn ¶ added in v0.7.0
RemoveHeaderOn before removes header with name, yields (calls func) once it gets found
func (*Request) ReplaceHeader ¶
func (hs *Request) ReplaceHeader(header Header)
ReplaceHeader replaces first header with same name
func (*Request) Route ¶
func (hs *Request) Route() (*RouteHeader, bool)
func (*Request) StartLineWrite ¶
func (req *Request) StartLineWrite(buffer io.StringWriter)
func (*Request) StringWrite ¶
func (req *Request) StringWrite(buffer io.StringWriter)
type RequestMethod ¶
type RequestMethod string
const ( INVITE RequestMethod = "INVITE" ACK RequestMethod = "ACK" CANCEL RequestMethod = "CANCEL" BYE RequestMethod = "BYE" REGISTER RequestMethod = "REGISTER" OPTIONS RequestMethod = "OPTIONS" SUBSCRIBE RequestMethod = "SUBSCRIBE" NOTIFY RequestMethod = "NOTIFY" REFER RequestMethod = "REFER" INFO RequestMethod = "INFO" MESSAGE RequestMethod = "MESSAGE" PRACK RequestMethod = "PRACK" UPDATE RequestMethod = "UPDATE" PUBLISH RequestMethod = "PUBLISH" )
method names are defined here as constants for convenience.
func (RequestMethod) String ¶
func (r RequestMethod) String() string
type Response ¶
type Response struct {
MessageData
Reason string // e.g. "200 OK"
StatusCode StatusCode // e.g. 200
}
Response RFC 3261 - 7.2.
func CopyResponse ¶
func NewResponse ¶
func NewResponse( statusCode StatusCode, reason string, ) *Response
NewResponse creates base structure of response.
func NewResponseFromRequest ¶
func NewResponseFromRequest( req *Request, statusCode StatusCode, reason string, body []byte, ) *Response
RFC 3261 - 8.2.6
func NewSDPResponseFromRequest ¶ added in v0.13.1
NewSDPResponseFromRequest is wrapper for 200 response with SDP body
func (*Response) AppendHeader ¶
func (hs *Response) AppendHeader(header Header)
AppendHeader adds header at end of header list
func (*Response) AppendHeaderAfter ¶
AppendHeaderAfter adds header after specified header. In case header does not exist normal AppendHeader is called Use it only if you need it
func (*Response) CSeq ¶
func (hs *Response) CSeq() (*CSeqHeader, bool)
func (*Response) CallID ¶
func (hs *Response) CallID() (*CallIDHeader, bool)
func (*Response) CloneHeaders ¶
func (hs *Response) CloneHeaders() []Header
CloneHeaders returns all cloned headers in slice.
func (*Response) Contact ¶
func (hs *Response) Contact() (*ContactHeader, bool)
func (*Response) ContentLength ¶
func (hs *Response) ContentLength() (*ContentLengthHeader, bool)
func (*Response) ContentType ¶
func (hs *Response) ContentType() (*ContentTypeHeader, bool)
func (*Response) Destination ¶
func (*Response) From ¶
func (hs *Response) From() (*FromHeader, bool)
func (*Response) GetHeader ¶
GetHeader returns Header if exists, otherwise nil is returned Use lower case to avoid allocs Headers are pointers, always Clone them for change
func (*Response) GetHeaders ¶
GetHeaders returns list of headers with same name Use lower case to avoid allocs Headers are pointers, always Clone them for change
func (*Response) IsClientError ¶
func (*Response) IsGlobalError ¶
func (*Response) IsProvisional ¶
func (*Response) IsRedirection ¶
func (*Response) IsServerError ¶
func (*Response) MaxForwards ¶ added in v0.7.2
func (hs *Response) MaxForwards() (*MaxForwardsHeader, bool)
func (*Response) PrependHeader ¶
func (hs *Response) PrependHeader(headers ...Header)
PrependHeader adds header to the front of header list using as list reduces need of realloc underneath array
func (*Response) RecordRoute ¶
func (hs *Response) RecordRoute() (*RecordRouteHeader, bool)
func (*Response) RemoveHeader ¶
RemoveHeader removes header by name
func (*Response) RemoveHeaderOn ¶ added in v0.7.0
RemoveHeaderOn before removes header with name, yields (calls func) once it gets found
func (*Response) ReplaceHeader ¶
func (hs *Response) ReplaceHeader(header Header)
ReplaceHeader replaces first header with same name
func (*Response) Route ¶
func (hs *Response) Route() (*RouteHeader, bool)
func (*Response) StartLineWrite ¶
func (res *Response) StartLineWrite(buffer io.StringWriter)
func (*Response) StringWrite ¶
func (res *Response) StringWrite(buffer io.StringWriter)
type RouteHeader ¶
type RouteHeader struct {
Address Uri
}
RouteHeader is Route header representation.
func (*RouteHeader) Clone ¶
func (h *RouteHeader) Clone() *RouteHeader
func (*RouteHeader) Name ¶
func (h *RouteHeader) Name() string
func (*RouteHeader) String ¶
func (h *RouteHeader) String() string
func (*RouteHeader) StringWrite ¶
func (h *RouteHeader) StringWrite(buffer io.StringWriter)
func (*RouteHeader) Value ¶
func (h *RouteHeader) Value() string
func (*RouteHeader) ValueStringWrite ¶
func (h *RouteHeader) ValueStringWrite(buffer io.StringWriter)
type ServerTransaction ¶
type ServerTransaction interface {
Transaction
Respond(res *Response) error
Acks() <-chan *Request
Cancels() <-chan *Request
}
type StatusCode ¶
type StatusCode int
StatusCode - response status code: 1xx - 6xx
const ( // https://datatracker.ietf.org/doc/html/rfc3261#section-21 StatusTrying StatusCode = 100 StatusRinging StatusCode = 180 StatusCallIsForwarded StatusCode = 181 StatusQueued StatusCode = 182 StatusSessionInProgress StatusCode = 183 StatusOK StatusCode = 200 StatusMovedPermanently StatusCode = 301 StatusMovedTemporarily StatusCode = 302 StatusUseProxy StatusCode = 305 StatusBadRequest StatusCode = 400 StatusPaymentRequired StatusCode = 402 StatusForbidden StatusCode = 403 StatusNotFound StatusCode = 404 StatusMethodNotAllowed StatusCode = 405 StatusNotAcceptable StatusCode = 406 StatusProxyAuthRequired StatusCode = 407 StatusRequestTimeout StatusCode = 408 StatusConflict StatusCode = 409 StatusGone StatusCode = 410 StatusRequestEntityTooLarge StatusCode = 413 StatusRequestURITooLong StatusCode = 414 StatusUnsupportedMediaType StatusCode = 415 StatusRequestedRangeNotSatisfiable StatusCode = 416 StatusBadExtension StatusCode = 420 StatusExtensionRequired StatusCode = 421 StatusIntervalToBrief StatusCode = 423 StatusCallTransactionDoesNotExists StatusCode = 481 StatusLoopDetected StatusCode = 482 StatusTooManyHops StatusCode = 483 StatusAddressIncomplete StatusCode = 484 StatusAmbiguous StatusCode = 485 StatusBusyHere StatusCode = 486 StatusRequestTerminated StatusCode = 487 StatusNotAcceptableHere StatusCode = 488 StatusInternalServerError StatusCode = 500 StatusNotImplemented StatusCode = 501 StatusBadGateway StatusCode = 502 StatusGatewayTimeout StatusCode = 504 StatusVersionNotSupported StatusCode = 505 StatusMessageTooLarge StatusCode = 513 StatusGlobalBusyEverywhere StatusCode = 600 StatusGlobalDecline StatusCode = 603 StatusGlobalDoesNotExistAnywhere StatusCode = 604 StatusGlobalNotAcceptable StatusCode = 606 )
type ToHeader ¶
type ToHeader struct {
// The display name from the header, may be omitted.
DisplayName string
Address Uri
// Any parameters present in the header.
Params HeaderParams
}
ToHeader introduces SIP 'To' header
func (*ToHeader) StringWrite ¶
func (h *ToHeader) StringWrite(buffer io.StringWriter)
func (*ToHeader) ValueStringWrite ¶
func (h *ToHeader) ValueStringWrite(buffer io.StringWriter)
type Transaction ¶
type Transaction interface {
// Terminate will terminate transaction
Terminate()
// Done when transaction fsm terminates. Can be called multiple times
Done() <-chan struct{}
// Last error. Useful to check when transaction terminates
Err() error
}
type Uri ¶
type Uri struct {
// True if and only if the URI is a SIPS URI.
Encrypted bool
Wildcard bool
// The user part of the URI: the 'joe' in sip:joe@bloggs.com
// This is a pointer, so that URIs without a user part can have 'nil'.
User string
// The password field of the URI. This is represented in the URI as joe:hunter2@bloggs.com.
// Note that if a URI has a password field, it *must* have a user field as well.
// Note that RFC 3261 strongly recommends against the use of password fields in SIP URIs,
// as they are fundamentally insecure.
Password string
// The host part of the URI. This can be a domain, or a string representation of an IP address.
Host string
// The port part of the URI. This is optional, and can be empty.
Port int
// Any parameters associated with the URI.
// These are used to provide information about requests that may be constructed from the URI.
// (For more details, see RFC 3261 section 19.1.1).
// These appear as a semicolon-separated list of key=value pairs following the host[:port] part.
UriParams HeaderParams
// Any headers to be included on requests constructed from this URI.
// These appear as a '&'-separated list at the end of the URI, introduced by '?'.
Headers HeaderParams
}
Uri is parsed form of sip:user:password@host:port;uri-parameters?headers In case of `sips:“ Encrypted is set to true
func (*Uri) IsEncrypted ¶
IsEncrypted returns true if uri is SIPS uri
func (*Uri) StringWrite ¶
func (uri *Uri) StringWrite(buffer io.StringWriter)
StringWrite writes uri string to buffer
type ViaHeader ¶
type ViaHeader struct {
// E.g. 'SIP'.
ProtocolName string
// E.g. '2.0'.
ProtocolVersion string
Transport string
// TODO consider changing Host Port as struct Addr from transport
Host string
Port int // This is optional
Params HeaderParams
}
ViaHeader is Via header representation. It can be linked list of multiple via if they are part of one header
func (*ViaHeader) StringWrite ¶
func (h *ViaHeader) StringWrite(buffer io.StringWriter)
func (*ViaHeader) ValueStringWrite ¶
func (h *ViaHeader) ValueStringWrite(buffer io.StringWriter)