Versions in this module Expand all Collapse all v0 v0.22.3 Sep 2, 2024 Changes in this version + const DefaultHost + const DefaultProtocol + const DefaultTcpPort + const DefaultTlsPort + const DefaultUdpPort + const DefaultWsPort + const DefaultWssPort + const FsmInputNone + const MTU + const RFC3261BranchMagicCookie + const TransportFixedLengthMessage + const TransportTCP + const TransportTLS + const TransportUDP + const TransportWS + const TransportWSS + var ErrParseEOF = errors.New("EOF on reading line") + var ErrParseLineNoCRLF = errors.New("line has no CRLF") + var ErrParseMoreMessages = errors.New("Stream has more message") + var ErrParseReadBodyIncomplete = errors.New("reading body incomplete") + var ErrParseSipPartial = errors.New("SIP partial data") + var ErrTransactionTimeout = errors.New("transaction timeout") + var ErrTransactionTransport = errors.New("transaction transport error") + var ErrTransportNotSuported = errors.New("protocol not supported") + var ErrUDPMTUCongestion = errors.New("size of packet larger than MTU") + var IdleConnection int = 1 + var SIPDebug bool + var T1 time.Duration + var T2 time.Duration + var T4 time.Duration + var Timer_1xx = 200 * time.Millisecond + var Timer_A time.Duration + var Timer_B time.Duration + var Timer_D time.Duration + var Timer_E time.Duration + var Timer_F time.Duration + var Timer_G time.Duration + var Timer_H time.Duration + var Timer_I time.Duration + var Timer_J time.Duration + var Timer_K time.Duration + var Timer_L time.Duration + var Timer_M time.Duration + var TransactionFSMDebug bool + var TxSeperator = "__" + var UDPMTUSize = 1500 + var UDPUseConnectedConnection = false + var WebSocketProtocols = []string + 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 IsReliable(network string) bool + func MakeClientTxKey(msg Message) (string, error) + func MakeDialogID(callID, innerID, externalID string) string + func MakeDialogIDFromRequest(msg *Request) (string, error) + func MakeDialogIDFromResponse(msg *Response) (string, error) + func MakeServerTxKey(msg Message) (string, error) + func MessageShortString(msg Message) string + func NetworkToLower(network string) 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 ResolveInterfacesIP(network string, targetIP net.IP) (net.IP, net.Interface, error) + func ResolveSelfIP() (net.IP, error) + func SetTimers(t1, t2, t4 time.Duration) + func SplitByWhitespace(text string) []string + func UACReadRequestDialogID(msg *Request) (string, error) + func UASReadRequestDialogID(msg *Request) (string, error) + 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 Addr struct + Hostname string + IP net.IP + Port int + func (a *Addr) String() string + type CSeqHeader struct + MethodName RequestMethod + SeqNo uint32 + func (h *CSeqHeader) Name() string + func (h *CSeqHeader) String() string + func (h *CSeqHeader) StringWrite(buffer io.StringWriter) + func (h *CSeqHeader) Value() string + func (h *CSeqHeader) ValueStringWrite(buffer io.StringWriter) + type CallIDHeader string + func (h *CallIDHeader) Name() string + func (h *CallIDHeader) String() string + func (h *CallIDHeader) StringWrite(buffer io.StringWriter) + func (h *CallIDHeader) Value() string + type ClientTransaction interface + Cancel func() error + Responses func() <-chan *Response + type ClientTx struct + func NewClientTx(key string, origin *Request, conn Connection, logger zerolog.Logger) *ClientTx + func (tx *ClientTx) Cancel() error + func (tx *ClientTx) Done() <-chan struct{} + func (tx *ClientTx) Err() error + func (tx *ClientTx) Init() error + func (tx *ClientTx) Key() string + func (tx *ClientTx) OnTerminate(f FnTxTerminate) + func (tx *ClientTx) Origin() *Request + func (tx *ClientTx) Responses() <-chan *Response + func (tx *ClientTx) String() string + func (tx *ClientTx) Terminate() + type Connection interface + Close func() error + LocalAddr func() net.Addr + Ref func(i int) int + TryClose func() (int, error) + WriteMsg func(msg Message) error + type ConnectionPool struct + func NewConnectionPool() ConnectionPool + func (p *ConnectionPool) Add(a string, c Connection) + func (p *ConnectionPool) AddIfNotExists(a string, c Connection) + func (p *ConnectionPool) Clear() + func (p *ConnectionPool) CloseAndDelete(c Connection, addr string) + func (p *ConnectionPool) Delete(addr string) + func (p *ConnectionPool) DeleteMultiple(addrs []string) + func (p *ConnectionPool) Get(a string) (c Connection) + func (p *ConnectionPool) Size() int + type ContactHeader struct + Address Uri + DisplayName string + Params HeaderParams + func (h *ContactHeader) Clone() *ContactHeader + func (h *ContactHeader) Name() string + func (h *ContactHeader) String() string + func (h *ContactHeader) StringWrite(buffer io.StringWriter) + func (h *ContactHeader) Value() string + type ContentLengthHeader uint32 + func (h *ContentLengthHeader) Name() string + func (h ContentLengthHeader) String() string + func (h ContentLengthHeader) StringWrite(buffer io.StringWriter) + func (h ContentLengthHeader) Value() string + type ContentTypeHeader string + func (h *ContentTypeHeader) Name() string + func (h *ContentTypeHeader) String() string + func (h *ContentTypeHeader) StringWrite(buffer io.StringWriter) + func (h *ContentTypeHeader) Value() string + type CopyHeader interface + type DialogState int + const DialogStateConfirmed + const DialogStateEnded + const DialogStateEstablished + func (s DialogState) String() string + type ErrorHandler func(err error) + type ExpiresHeader uint32 + func (h *ExpiresHeader) Name() string + func (h *ExpiresHeader) String() string + func (h *ExpiresHeader) StringWrite(buffer io.StringWriter) + func (h ExpiresHeader) Value() string + type FnTxTerminate func(key string) + type FromHeader struct + Address Uri + DisplayName string + Params HeaderParams + func (h *FromHeader) Name() string + func (h *FromHeader) String() string + func (h *FromHeader) StringWrite(buffer io.StringWriter) + func (h *FromHeader) Value() string + func (h *FromHeader) ValueStringWrite(buffer io.StringWriter) + func (header *FromHeader) Next() Header + type Header interface + Name func() string + String func() string + StringWrite func(w io.StringWriter) + Value func() string + func HeaderClone(h Header) Header + func NewHeader(name, value string) Header + type HeaderKV struct + K string + V string + type HeaderParams map[string]string + func NewParams() 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 func(headerName string, headerData string) (Header, error) + type MaxForwardsHeader uint32 + func (h *MaxForwardsHeader) Dec() + func (h *MaxForwardsHeader) Name() string + func (h *MaxForwardsHeader) String() string + func (h *MaxForwardsHeader) StringWrite(buffer io.StringWriter) + func (h *MaxForwardsHeader) Value() string + func (h MaxForwardsHeader) Val() uint32 + type Message interface + AppendHeader func(header Header) + Body func() []byte + CSeq func() *CSeqHeader + CallID func() *CallIDHeader + Destination func() string + From func() *FromHeader + GetHeaders func(name string) []Header + PrependHeader func(header ...Header) + SetBody func(body []byte) + SetDestination func(dest string) + SetSource func(src string) + SetTransport func(tp string) + Source func() string + String func() string + StringWrite func(io.StringWriter) + To func() *ToHeader + Transport func() string + Via func() *ViaHeader + func ParseMessage(msgData []byte) (Message, error) + type MessageData struct + SipVersion string + func (hs *MessageData) AppendHeader(header Header) + func (hs *MessageData) AppendHeaderAfter(header Header, name string) + func (hs *MessageData) CSeq() *CSeqHeader + func (hs *MessageData) CallID() *CallIDHeader + func (hs *MessageData) CloneHeaders() []Header + func (hs *MessageData) Contact() *ContactHeader + func (hs *MessageData) ContentLength() *ContentLengthHeader + func (hs *MessageData) ContentType() *ContentTypeHeader + func (hs *MessageData) From() *FromHeader + func (hs *MessageData) GetHeader(name string) Header + func (hs *MessageData) GetHeaders(name string) []Header + func (hs *MessageData) Headers() []Header + func (hs *MessageData) MaxForwards() *MaxForwardsHeader + func (hs *MessageData) PrependHeader(headers ...Header) + func (hs *MessageData) RecordRoute() *RecordRouteHeader + func (hs *MessageData) RemoveHeader(name string) (removed bool) + func (hs *MessageData) ReplaceHeader(header Header) + func (hs *MessageData) Route() *RouteHeader + func (hs *MessageData) String() string + func (hs *MessageData) StringWrite(buffer io.StringWriter) + func (hs *MessageData) To() *ToHeader + func (hs *MessageData) Via() *ViaHeader + func (msg *MessageData) Body() []byte + func (msg *MessageData) Destination() string + 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 (msg *MessageData) Transport() string + type MessageHandler func(msg Message) + type Params interface + Add func(key string, val string) Params + Clone func() Params + Equals func(params interface{}) bool + Get func(key string) (string, bool) + Has func(key string) bool + Items func() map[string]string + Keys func() []string + Length func() int + Remove func(key string) Params + String func() string + ToString func(sep uint8) string + ToStringWrite func(sep uint8, buffer io.StringWriter) + type Parser struct + func NewParser(options ...ParserOption) *Parser + func (p *Parser) NewSIPStream() *ParserStream + func (p *Parser) ParseSIP(data []byte) (msg Message, err error) + type ParserOption func(p *Parser) + func WithHeadersParsers(m map[string]HeaderParser) ParserOption + func WithParserLogger(logger zerolog.Logger) ParserOption + type ParserStream struct + func (p *ParserStream) ParseSIPStream(data []byte) (msgs []Message, err error) + type RecordRouteHeader struct + Address Uri + 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 struct + Method RequestMethod + Recipient Uri + func CopyRequest(req *Request) *Request + func NewAckRequest(inviteRequest *Request, inviteResponse *Response, body []byte) *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 + func (hs *Request) CallID() *CallIDHeader + func (hs *Request) CloneHeaders() []Header + func (hs *Request) Contact() *ContactHeader + func (hs *Request) ContentLength() *ContentLengthHeader + func (hs *Request) ContentType() *ContentTypeHeader + func (hs *Request) From() *FromHeader + func (hs *Request) GetHeader(name string) Header + func (hs *Request) GetHeaders(name string) []Header + func (hs *Request) Headers() []Header + func (hs *Request) MaxForwards() *MaxForwardsHeader + func (hs *Request) PrependHeader(headers ...Header) + func (hs *Request) RecordRoute() *RecordRouteHeader + func (hs *Request) RemoveHeader(name string) (removed bool) + func (hs *Request) ReplaceHeader(header Header) + func (hs *Request) Route() *RouteHeader + func (hs *Request) To() *ToHeader + func (hs *Request) Via() *ViaHeader + func (req *Request) Clone() *Request + func (req *Request) Destination() string + func (req *Request) IsAck() bool + func (req *Request) IsCancel() bool + func (req *Request) IsInvite() 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 (req *Request) Transport() string + type RequestHandler func(req *Request, tx ServerTransaction) + type RequestMethod string + const ACK + const BYE + const CANCEL + const INFO + const INVITE + const MESSAGE + const NOTIFY + const OPTIONS + const PRACK + const PUBLISH + const REFER + const REGISTER + const SUBSCRIBE + const UPDATE + func (r RequestMethod) String() string + type Response struct + Reason string + StatusCode StatusCode + func CopyResponse(res *Response) *Response + func NewResponse(statusCode StatusCode, reason string) *Response + func NewResponseFromRequest(req *Request, statusCode StatusCode, reason string, body []byte) *Response + func NewSDPResponseFromRequest(req *Request, body []byte) *Response + func (hs *Response) AppendHeader(header Header) + func (hs *Response) AppendHeaderAfter(header Header, name string) + func (hs *Response) CSeq() *CSeqHeader + func (hs *Response) CallID() *CallIDHeader + func (hs *Response) CloneHeaders() []Header + func (hs *Response) Contact() *ContactHeader + func (hs *Response) ContentLength() *ContentLengthHeader + func (hs *Response) ContentType() *ContentTypeHeader + func (hs *Response) From() *FromHeader + func (hs *Response) GetHeader(name string) Header + func (hs *Response) GetHeaders(name string) []Header + func (hs *Response) Headers() []Header + func (hs *Response) MaxForwards() *MaxForwardsHeader + func (hs *Response) PrependHeader(headers ...Header) + func (hs *Response) RecordRoute() *RecordRouteHeader + func (hs *Response) RemoveHeader(name string) (removed bool) + func (hs *Response) ReplaceHeader(header Header) + func (hs *Response) Route() *RouteHeader + func (hs *Response) To() *ToHeader + func (hs *Response) Via() *ViaHeader + func (res *Response) Clone() *Response + func (res *Response) Destination() string + 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 (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 (res *Response) Transport() string + type RouteHeader struct + Address Uri + func (h *RouteHeader) Clone() *RouteHeader + func (h *RouteHeader) Name() string + func (h *RouteHeader) String() string + func (h *RouteHeader) StringWrite(buffer io.StringWriter) + func (h *RouteHeader) Value() string + func (h *RouteHeader) ValueStringWrite(buffer io.StringWriter) + type ServerTransaction interface + Acks func() <-chan *Request + Cancels func() <-chan *Request + Respond func(res *Response) error + type ServerTx struct + func NewServerTx(key string, origin *Request, conn Connection, logger zerolog.Logger) *ServerTx + func (tx *ServerTx) Acks() <-chan *Request + func (tx *ServerTx) Cancels() <-chan *Request + func (tx *ServerTx) Done() <-chan struct{} + func (tx *ServerTx) Err() error + func (tx *ServerTx) Init() error + func (tx *ServerTx) Key() string + func (tx *ServerTx) OnTerminate(f FnTxTerminate) + func (tx *ServerTx) Origin() *Request + func (tx *ServerTx) Receive(req *Request) error + func (tx *ServerTx) Respond(res *Response) error + func (tx *ServerTx) State() + func (tx *ServerTx) String() string + func (tx *ServerTx) Terminate() + type StatusCode int + const StatusAccepted + const StatusAddressIncomplete + const StatusAmbiguous + const StatusBadExtension + const StatusBadGateway + const StatusBadRequest + const StatusBusyHere + const StatusCallIsForwarded + const StatusCallTransactionDoesNotExists + const StatusConflict + const StatusExtensionRequired + const StatusForbidden + const StatusGatewayTimeout + const StatusGlobalBusyEverywhere + const StatusGlobalDecline + const StatusGlobalDoesNotExistAnywhere + const StatusGlobalNotAcceptable + const StatusGone + const StatusInternalServerError + const StatusIntervalToBrief + const StatusLoopDetected + const StatusMessageTooLarge + const StatusMethodNotAllowed + const StatusMovedPermanently + const StatusMovedTemporarily + const StatusNotAcceptable + const StatusNotAcceptableHere + const StatusNotFound + const StatusNotImplemented + const StatusOK + const StatusPaymentRequired + const StatusProxyAuthRequired + const StatusQueued + const StatusRequestEntityTooLarge + const StatusRequestTerminated + const StatusRequestTimeout + const StatusRequestURITooLong + const StatusRequestedRangeNotSatisfiable + const StatusRinging + const StatusServiceUnavailable + const StatusSessionInProgress + const StatusTemporarilyUnavailable + const StatusTooManyHops + const StatusTrying + const StatusUnauthorized + const StatusUnsupportedMediaType + const StatusUseProxy + const StatusVersionNotSupported + type TCPConnection struct + func (c *TCPConnection) Close() error + func (c *TCPConnection) Read(b []byte) (n int, err error) + func (c *TCPConnection) Ref(i int) int + func (c *TCPConnection) TryClose() (int, error) + func (c *TCPConnection) Write(b []byte) (n int, err error) + func (c *TCPConnection) WriteMsg(msg Message) error + type ToHeader struct + Address Uri + DisplayName string + Params HeaderParams + func (h *ToHeader) Name() string + func (h *ToHeader) String() string + func (h *ToHeader) StringWrite(buffer io.StringWriter) + func (h *ToHeader) Value() string + func (h *ToHeader) ValueStringWrite(buffer io.StringWriter) + func (header *ToHeader) Next() Header + type Transaction interface + Done func() <-chan struct{} + Err func() error + Terminate func() + type TransactionLayer struct + func NewTransactionLayer(tpl *TransportLayer) *TransactionLayer + func (txl *TransactionLayer) Close() + func (txl *TransactionLayer) OnRequest(h RequestHandler) + func (txl *TransactionLayer) Request(ctx context.Context, req *Request) (*ClientTx, error) + func (txl *TransactionLayer) Respond(res *Response) (*ServerTx, error) + func (txl *TransactionLayer) Transport() *TransportLayer + func (txl *TransactionLayer) UnhandledResponseHandler(f UnhandledResponseHandler) + type Transport interface + Close func() error + CreateConnection func(ctx context.Context, laddr Addr, raddr Addr, handler MessageHandler) (Connection, error) + GetConnection func(addr string) (Connection, error) + Network func() string + String func() string + type TransportLayer struct + ConnectionReuse bool + DNSPreferSRV bool + func NewTransportLayer(dnsResolver *net.Resolver, sipparser *Parser, tlsConfig *tls.Config) *TransportLayer + func (l *TransportLayer) ClientRequestConnection(ctx context.Context, req *Request) (c Connection, err error) + func (l *TransportLayer) Close() error + func (l *TransportLayer) GetConnection(network, addr string) (Connection, error) + func (l *TransportLayer) GetListenPort(network string) int + func (l *TransportLayer) OnMessage(h MessageHandler) + func (l *TransportLayer) ServeTCP(c net.Listener) error + func (l *TransportLayer) ServeTLS(c net.Listener) error + func (l *TransportLayer) ServeUDP(c net.PacketConn) error + func (l *TransportLayer) ServeWS(c net.Listener) error + func (l *TransportLayer) ServeWSS(c net.Listener) error + func (l *TransportLayer) WriteMsg(msg Message) error + func (l *TransportLayer) WriteMsgTo(msg Message, addr string, network string) error + type UDPConnection struct + Conn net.Conn + Listener bool + PacketAddr string + PacketConn net.PacketConn + func (c *UDPConnection) Close() error + func (c *UDPConnection) LocalAddr() net.Addr + func (c *UDPConnection) Read(b []byte) (n int, err error) + func (c *UDPConnection) ReadFrom(b []byte) (n int, addr net.Addr, err error) + func (c *UDPConnection) Ref(i int) int + func (c *UDPConnection) RemoteAddr() net.Addr + func (c *UDPConnection) TryClose() (int, error) + func (c *UDPConnection) Write(b []byte) (n int, err error) + func (c *UDPConnection) WriteMsg(msg Message) error + func (c *UDPConnection) WriteTo(b []byte, addr net.Addr) (n int, err error) + type UnhandledResponseHandler func(req *Response) + type Uri struct + Encrypted bool + Headers HeaderParams + Host string + Password string + Port int + UriParams HeaderParams + User string + Wildcard bool + func (uri *Uri) Addr() string + func (uri *Uri) Clone() *Uri + func (uri *Uri) Endpoint() string + func (uri *Uri) HostPort() string + func (uri *Uri) IsEncrypted() bool + func (uri *Uri) String() string + func (uri *Uri) StringWrite(buffer io.StringWriter) + type ViaHeader struct + Host string + Params HeaderParams + Port int + ProtocolName string + ProtocolVersion string + Transport string + func (h *ViaHeader) Clone() *ViaHeader + func (h *ViaHeader) Name() string + func (h *ViaHeader) String() string + func (h *ViaHeader) StringWrite(buffer io.StringWriter) + func (h *ViaHeader) Value() string + func (h *ViaHeader) ValueStringWrite(buffer io.StringWriter) + func (hop *ViaHeader) SentBy() string + type WSConnection struct + func (c *WSConnection) Close() error + func (c *WSConnection) Read(b []byte) (n int, err error) + func (c *WSConnection) Ref(i int) int + func (c *WSConnection) TryClose() (int, error) + func (c *WSConnection) Write(b []byte) (n int, err error) + func (c *WSConnection) WriteMsg(msg Message) error