sip

package
v1.4.21 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MethodInvite   = "INVITE"
	MethodACK      = "ACK"
	MethodCancel   = "CANCEL"
	MethodBYE      = "BYE"
	MethodRegister = "REGISTER"
	MethodOptions  = "OPTIONS"
	// SUBSCRIBE  = "SUBSCRIBE"
	MethodNotify = "NOTIFY"
	// REFER    = "REFER"
	MethodInfo    = "INFO"
	MethodMessage = "MESSAGE"
)

It's nicer to avoid using raw strings to represent methods, so the following standard method names are defined here as constants for convenience.

View Source
const RFC3261BranchMagicCookie = "z9hG4bK"

RFC3261BranchMagicCookie RFC3261BranchMagicCookie

Variables

View Source
var (
	// CatalogXML 获取设备列表xml样式
	CatalogXML = `<?xml version="1.0" encoding="GB2312"?>
<Query>
<CmdType>Catalog</CmdType>
<SN>%d</SN>
<DeviceID>%s</DeviceID>
</Query>
`
	// RecordInfoXML 获取录像文件列表xml样式
	RecordInfoXML = `` /* 210-byte string literal not displayed */

	// DeviceInfoXML 查询设备详情xml样式
	DeviceInfoXML = `<?xml version="1.0" encoding="GB2312"?>
<Query>
<CmdType>DeviceInfo</CmdType>
<SN>%d</SN>
<DeviceID>%s</DeviceID>
</Query>
`
)
View Source
var ContentTypeSDP = ContentType("APPLICATION/SDP")

ContentTypeSDP SDP contenttype

View Source
var ContentTypeXML = ContentType("Application/MANSCDP+xml")

ContentTypeXML XML contenttype

View Source
var DefaultProtocol = "udp"

DefaultProtocol DefaultProtocol

View Source
var DefaultSipVersion = "SIP/2.0"

DefaultSipVersion DefaultSipVersion

Functions

func CalcResponse

func CalcResponse(username, realm, password, method, uri, nonce, qop, cnonce, nc string) string

CalcResponse Authorization response https://www.ietf.org/rfc/rfc2617.txt

func CopyHeaders

func CopyHeaders(name string, from, to Message)

CopyHeaders Copy all headers of one type from one message to another. Appending to any headers that were already there.

func GbkToUtf8

func GbkToUtf8(s []byte) ([]byte, error)

GBK 转 UTF-8

func GenerateBranch

func GenerateBranch() string

GenerateBranch returns random unique branch ID.

func GetCatalogXML

func GetCatalogXML(id string) []byte

GetCatalogXML 获取NVR下设备列表指令

func GetDeviceInfoXML

func GetDeviceInfoXML(id string) []byte

GetDeviceInfoXML 获取设备详情指令

func GetRecordInfoXML

func GetRecordInfoXML(id string, sceqNo int, start, end int64) []byte

GetRecordInfoXML 获取录像文件列表指令

func GetRequest

func GetRequest(url string) ([]byte, error)

GetRequest GetRequest

func JSONDecode

func JSONDecode(data []byte, obj any) error

JSONDecode JSONDecode

func JSONEncode

func JSONEncode(data any) []byte

JSONEncode JSONEncode

func Max

func Max(a, b int64) int64

Max Max

func NewError

func NewError(err error, params ...any) error

NewError NewError

func ParseAddressValue

func ParseAddressValue(addressText string) (
	displayName MaybeString,
	uri *URI,
	headerParams Params,
	err error,
)

ParseAddressValue parses an address - such as from a From, To, or Contact header. It returns:

  • a MaybeString containing the display name (or not)
  • a parsed SipUri object
  • a map containing any header parameters present
  • the error object

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; addresses in that form should be handled by ParseAddressValues.

func ParseAddressValues

func ParseAddressValues(addresses string) (
	displayNames []MaybeString,
	uris []*URI,
	headerParams []Params,
	err error,
)

ParseAddressValues parses a comma-separated list of addresses, returning any display names and header params, as well as the SIP URIs themselves. ParseAddressValues is aware of < > bracketing and quoting, and will not break on commas within these structures.

func ParseStatusLine

func ParseStatusLine(statusLine string) (
	sipVersion string, statusCode int, reasonPhrase string, err error,
)

ParseStatusLine the first line of a SIP response, e.g:

SIP/2.0 200 OK
SIP/1.0 403 Forbidden

func PostJSONRequest

func PostJSONRequest(url string, data any) ([]byte, error)

PostJSONRequest PostJSONRequest

func PostRequest

func PostRequest(url string, bodyType string, body io.Reader) ([]byte, error)

PostRequest PostRequest

func RandInt

func RandInt(min, max int) int

func ResolveSelfIP

func ResolveSelfIP() (net.IP, error)

ResolveSelfIP ResolveSelfIP

func SplitByWhitespace

func SplitByWhitespace(text string) []string

SplitByWhitespace Splits the given string into sections, separated by one or more characters from c_ABNF_WS.

func Uint16PtrEq

func Uint16PtrEq(a *uint16, b *uint16) bool

Uint16PtrEq Check two uint16 pointers for equality as follows: - If neither pointer is nil, check equality of the underlying uint16s. - If either pointer is nil, return true if and only if they both are.

func Utf8ToGbk

func Utf8ToGbk(s []byte) ([]byte, error)

UTF-8 转 GBK

func XMLDecode

func XMLDecode(data []byte, v any) error

XMLDecode 解码 xml

func XMLEncode

func XMLEncode(data any) ([]byte, error)

XMLEncode XML编码器

Types

type Accept

type Accept string

Accept Accept

func (*Accept) Clone

func (ct *Accept) Clone() Header

Clone Clone

func (*Accept) Equals

func (ct *Accept) Equals(other any) bool

Equals Equals

func (*Accept) Name

func (ct *Accept) Name() string

Name Name

func (Accept) String

func (ct Accept) String() string

type Address

type Address struct {
	DisplayName MaybeString
	URI         *URI
	Params      Params
}

Address Address

func NewAddressFromFromHeader

func NewAddressFromFromHeader(from *FromHeader) *Address

NewAddressFromFromHeader NewAddressFromFromHeader

func (*Address) Clone

func (addr *Address) Clone() *Address

Clone Clone

func (Address) String

func (addr Address) String() string

type AllowHeader

type AllowHeader []string

AllowHeader AllowHeader

func (AllowHeader) Clone

func (allow AllowHeader) Clone() Header

Clone Clone

func (AllowHeader) Equals

func (allow AllowHeader) Equals(other any) bool

Equals equals

func (AllowHeader) Name

func (allow AllowHeader) Name() string

Name Name

func (AllowHeader) String

func (allow AllowHeader) String() string

type Authorization

type Authorization struct {
	Data map[string]string
	// contains filtered or unexported fields
}

Authorization currently only Digest and MD5

func AuthFromValue

func AuthFromValue(value string) *Authorization

AuthFromValue AuthFromValue

func (*Authorization) CalcResponse

func (auth *Authorization) CalcResponse() string

CalcResponse CalcResponse

func (*Authorization) Get

func (auth *Authorization) Get(key string) string

Get Get

func (*Authorization) SetMethod

func (auth *Authorization) SetMethod(method string) *Authorization

SetMethod SetMethod

func (*Authorization) SetPassword

func (auth *Authorization) SetPassword(password string) *Authorization

SetPassword SetPassword

func (*Authorization) SetURI

func (auth *Authorization) SetURI(uri string) *Authorization

SetURI SetURI

func (*Authorization) SetUsername

func (auth *Authorization) SetUsername(username string) *Authorization

SetUsername SetUsername

func (*Authorization) String

func (auth *Authorization) String() string

type CSeq

type CSeq struct {
	SeqNo      uint32
	MethodName string
}

CSeq CSeq

func (*CSeq) Clone

func (cseq *CSeq) Clone() Header

Clone Clone

func (*CSeq) Equals

func (cseq *CSeq) Equals(other any) bool

Equals Equals

func (*CSeq) Name

func (cseq *CSeq) Name() string

Name Name

func (*CSeq) String

func (cseq *CSeq) String() string

type CallID

type CallID string

CallID - 'Call-ID' header.

func (*CallID) Clone

func (callId *CallID) Clone() Header

Clone Clone

func (*CallID) Equals

func (callId *CallID) Equals(other any) bool

Equals Equals

func (*CallID) Name

func (callId *CallID) Name() string

Name Name

func (CallID) String

func (callId CallID) String() string

type Collector

type Collector[T any] struct {
	// contains filtered or unexported fields
}

Collector . 1. 收集器 2. 分门别类 3. 定时同步,超时删除,删除之前再同步一次 4. 不会去重 如何使用? 1. 通过 NewCatalogRecv 创建一个新的收集器 2. s.createCh <- deviceID 3. s.catalog.msg <- &CollectorMsg[Channel]{Data: &c, Total: msg.SumNum, Key: msg.DeviceID}

func NewCollector

func NewCollector[T any](noRepeatFn NoRepeatFn[T]) *Collector[T]

newCollector 创建一个新的收集器 noRepeatFn 用于提前去重,避免重复数据存储

func (*Collector[T]) Run

func (c *Collector[T]) Run(key string)

func (*Collector[T]) Start

func (c *Collector[T]) Start(save func(string, []*T))

Start 启动定时任务检查和保存数据

func (*Collector[T]) Wait

func (c *Collector[T]) Wait(key string)

Wait 在执行 Start 以后,可以调用 Wait 等待

func (*Collector[T]) Write

func (c *Collector[T]) Write(info *CollectorMsg[T])

type CollectorMsg

type CollectorMsg[T any] struct {
	Key   string
	Data  *T
	Total int
}

type Connection

type Connection interface {
	net.Conn
	Network() string
	// String() string
	ReadFrom(buf []byte) (num int, raddr net.Addr, err error)
	WriteTo(buf []byte, raddr net.Addr) (num int, err error)
}

Connection Wrapper around net.Conn.

func NewTCPConnection

func NewTCPConnection(baseConn net.Conn) Connection

func NewUDPConnection

func NewUDPConnection(baseConn net.Conn) Connection

type ContactHeader

type ContactHeader struct {
	// The display name from the header, may be omitted.
	DisplayName MaybeString
	Address     *URI
	// Any parameters present in the header.
	Params Params
}

ContactHeader ContactHeader

func (*ContactHeader) Clone

func (contact *ContactHeader) Clone() Header

Clone Copy the header.

func (*ContactHeader) Equals

func (contact *ContactHeader) Equals(other any) bool

Equals Equals

func (*ContactHeader) Name

func (contact *ContactHeader) Name() string

Name Name

func (*ContactHeader) String

func (contact *ContactHeader) String() string

type Content

type Content[T any] struct {
	// contains filtered or unexported fields
}

type ContentLength

type ContentLength uint32

ContentLength ContentLength header

func (*ContentLength) Clone

func (contentLength *ContentLength) Clone() Header

Clone Clone

func (*ContentLength) Equals

func (contentLength *ContentLength) Equals(other any) bool

Equals Equals

func (*ContentLength) Name

func (contentLength *ContentLength) Name() string

Name Name

func (ContentLength) String

func (contentLength ContentLength) String() string

type ContentType

type ContentType string

ContentType ContentType

func (*ContentType) Clone

func (ct *ContentType) Clone() Header

Clone Clone

func (*ContentType) Equals

func (ct *ContentType) Equals(other any) bool

Equals Equals

func (*ContentType) Name

func (ct *ContentType) Name() string

Name Name

func (ContentType) String

func (ct ContentType) String() string

type Context

type Context struct {
	Request *Request
	Tx      *Transaction

	DeviceID string
	Host     string
	Port     string

	Source net.Addr
	To     *Address
	From   *Address

	Log *slog.Logger

	XGBVer string
	// contains filtered or unexported fields
}

func (*Context) Abort

func (c *Context) Abort()

func (*Context) AbortString

func (c *Context) AbortString(status int, msg string)

func (*Context) Get

func (c *Context) Get(k string) (any, bool)

func (*Context) GetHeader

func (c *Context) GetHeader(key string) string

func (*Context) GetMustInt

func (c *Context) GetMustInt(k string) int

func (*Context) GetMustString

func (c *Context) GetMustString(k string) string

func (*Context) IsAborted added in v1.3.34

func (c *Context) IsAborted() bool

IsAborted 返回当前链路是否已被中止

func (*Context) Next

func (c *Context) Next()

func (*Context) SendRequest

func (c *Context) SendRequest(method string, body []byte) (*Transaction, error)

func (*Context) Set

func (c *Context) Set(k string, v any)

func (*Context) String

func (c *Context) String(status int, msg string)

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error Error

func (*Error) Error

func (err *Error) Error() string

type Expires

type Expires uint32

Expires Expires

func (*Expires) Clone

func (expires *Expires) Clone() Header

Clone clone

func (*Expires) Equals

func (expires *Expires) Equals(other any) bool

Equals Equals

func (*Expires) Name

func (expires *Expires) Name() string

Name Name

func (Expires) String

func (expires Expires) String() string

type FromHeader

type FromHeader struct {
	// The display name from the header, may be omitted.
	DisplayName MaybeString

	Address *URI

	// Any parameters present in the header.
	Params Params
}

FromHeader FromHeader

func (*FromHeader) Clone

func (from *FromHeader) Clone() Header

Clone Copy the header.

func (*FromHeader) Equals

func (from *FromHeader) Equals(other any) bool

Equals Equals

func (*FromHeader) Name

func (from *FromHeader) Name() string

Name Name

func (*FromHeader) String

func (from *FromHeader) String() string

type GenericHeader

type GenericHeader struct {
	// The name of the header.
	HeaderName string
	// The contents of the header, including any parameters.
	// This is transparent data that is not natively understood by gossip.
	Contents string
}

GenericHeader Encapsulates a header that gossip does not natively support. This allows header data that is not understood to be parsed by gossip and relayed to the parent application.

func (*GenericHeader) Clone

func (header *GenericHeader) Clone() Header

Clone Copy the header.

func (*GenericHeader) Equals

func (header *GenericHeader) Equals(other any) bool

Equals Equals

func (*GenericHeader) Name

func (header *GenericHeader) Name() string

Name Pull out the header name.

func (*GenericHeader) String

func (header *GenericHeader) String() string

Convert the header to a flat string representation.

type HandlerFunc

type HandlerFunc func(*Context)
type Header interface {
	// Name returns header name.
	Name() string
	// Clone returns copy of header struct.
	Clone() Header
	String() string
	Equals(other any) bool
}

Header is a single SIP header.

func ParseHeader

func ParseHeader(headerText string) (headers []Header, err error)

ParseHeader ParseHeader

type HeaderParser

type HeaderParser func(headerName string, headerData string) ([]Header, error)

A HeaderParser is any function that turns raw header data into one or more Header objects. The HeaderParser will receive arguments of the form ("max-forwards", "70"). It should return a slice of headers, which should have length > 1 unless it also returns an error.

type HeadersBuilder

type HeadersBuilder struct {
	XGBVer *XGBVer
	// contains filtered or unexported fields
}

HeadersBuilder HeadersBuilder

func NewHeaderBuilder

func NewHeaderBuilder() *HeadersBuilder

NewHeaderBuilder NewHeaderBuilder

func (*HeadersBuilder) AddVia

func (hb *HeadersBuilder) AddVia(via *ViaHop) *HeadersBuilder

AddVia AddVia

func (*HeadersBuilder) Build

func (hb *HeadersBuilder) Build() []Header

Build 按参考实现的头顺序构建:Via → From → To → CallID → CSeq → ContentType → Contact → MaxForwards → UserAgent → Subject → XGBVer

func (*HeadersBuilder) SetCallID

func (hb *HeadersBuilder) SetCallID(callID *CallID) *HeadersBuilder

SetCallID SetCallID

func (*HeadersBuilder) SetContact

func (hb *HeadersBuilder) SetContact(address *Address) *HeadersBuilder

SetContact SetContact

func (*HeadersBuilder) SetContentType

func (hb *HeadersBuilder) SetContentType(contentType *ContentType) *HeadersBuilder

SetContentType SetContentType

func (*HeadersBuilder) SetFrom

func (hb *HeadersBuilder) SetFrom(address *Address) *HeadersBuilder

SetFrom FromHeader

func (*HeadersBuilder) SetMethod

func (hb *HeadersBuilder) SetMethod(method string) *HeadersBuilder

SetMethod SetMethod

func (*HeadersBuilder) SetSeqNo

func (hb *HeadersBuilder) SetSeqNo(seqNo uint) *HeadersBuilder

SetSeqNo SetSeqNo

func (*HeadersBuilder) SetSubject added in v1.3.34

func (hb *HeadersBuilder) SetSubject(v string) *HeadersBuilder

SetSubject 设置 Subject 头

func (*HeadersBuilder) SetTo

func (hb *HeadersBuilder) SetTo(address *Address) *HeadersBuilder

SetTo ToHeader

func (*HeadersBuilder) SetToWithParam

func (hb *HeadersBuilder) SetToWithParam(address *Address) *HeadersBuilder

SetTo ToHeader

func (*HeadersBuilder) SetXGBVer

func (hb *HeadersBuilder) SetXGBVer() *HeadersBuilder

type MaxForwards

type MaxForwards uint32

MaxForwards MaxForwards

func (*MaxForwards) Clone

func (maxForwards *MaxForwards) Clone() Header

Clone Clone

func (*MaxForwards) Equals

func (maxForwards *MaxForwards) Equals(other any) bool

Equals Equals

func (*MaxForwards) Name

func (maxForwards *MaxForwards) Name() string

Name Name

func (MaxForwards) String

func (maxForwards MaxForwards) String() string

type MaybeString

type MaybeString interface {
	String() string
	Equals(other any) bool
}

MaybeString wrapper

type Message

type Message interface {
	MessageID() MessageID

	Clone() Message
	// Start line returns message start line.
	StartLine() string
	// String returns string representation of SIP message in RFC 3261 form.
	String() string
	// SipVersion returns SIP protocol version.
	SipVersion() string
	// SetSipVersion sets SIP protocol version.
	SetSipVersion(version string)

	// Headers returns all message headers.
	Headers() []Header
	// GetHeaders returns slice of headers of the given type.
	GetHeaders(name string) []Header
	// AppendHeader appends header to message.
	AppendHeader(header Header)
	// PrependHeader prepends header to message.
	RemoveHeader(name string)

	// Body returns message body.
	Body() []byte
	// SetBody sets message body.
	SetBody(body []byte, setContentLength bool)

	/* Helper getters for common headers */
	// CallID returns 'Call-ID' header.
	CallID() (*CallID, bool)
	// Via returns the top 'Via' header field.
	Via() (ViaHeader, bool)
	// ViaHop returns the first segment of the top 'Via' header.
	ViaHop() (*ViaHop, bool)
	// From returns 'From' header field.
	From() (*FromHeader, bool)
	// To returns 'To' header field.
	To() (*ToHeader, bool)
	// CSeq returns 'CSeq' header field.
	CSeq() (*CSeq, bool)
	ContentLength() (*ContentLength, bool)
	ContentType() (*ContentType, bool)
	Contact() (*ContactHeader, bool)

	Transport() string
	Source() net.Addr
	SetSource(src net.Addr)
	Destination() net.Addr
	SetDestination(dest net.Addr)
	SetConnection(Connection)

	IsCancel() bool
	IsAck() bool
}

Message introduces common SIP message RFC 3261 - 7.

type MessageID

type MessageID string

MessageID MessageID

type MessageReceive

type MessageReceive struct {
	CmdType string `xml:"CmdType"`
	SN      int    `xml:"SN"`
}

type NoRepeatFn

type NoRepeatFn[T any] func(*T, *T) bool

type Observer

type Observer struct {
	// contains filtered or unexported fields
}

Observer 观察者

func NewObserver

func NewObserver() *Observer

NewObserver 创建观察者

func (*Observer) DefaultRegister

func (o *Observer) DefaultRegister(deviceID string)

DefaultRegister 默认的注册行为

func (*Observer) Notify

func (o *Observer) Notify(deviceID string, args ...string)

Notify 通知观察者

func (*Observer) Register

func (o *Observer) Register(deviceID string, duration time.Duration, fn ObserverHandler)

Register 同步等待观察者完成任务

func (*Observer) RegisterWithTimeout

func (o *Observer) RegisterWithTimeout(deviceID string, duration time.Duration)

RegisterWithTimeout 自定义等待时间

type ObserverHandler

type ObserverHandler func(deviceID string, args ...string) bool

ObserverHandler 返回 true 表示完成任务

type Packet

type Packet struct {
	// contains filtered or unexported fields
}

Packet Packet

type Params

type Params interface {
	Get(key string) (MaybeString, bool)
	Add(key string, val MaybeString) Params
	Clone() Params
	Equals(params any) bool
	ToString(sep uint8) string
	String() string
	Length() int
	Items() map[string]MaybeString
	Keys() []string
	Has(key string) bool
}

Params Generic list of parameters on a header.

func NewParams

func NewParams() Params

NewParams Create an empty set of parameters.

func ParseParams

func ParseParams(
	source string,
	start uint8,
	sep uint8,
	end uint8,
	quoteValues bool,
	permitSingletons bool,
) (
	params Params, consumed int, err error,
)

ParseParams General utility method for parsing 'key=value' parameters. Takes a string (source), ensures that it begins with the 'start' character provided, and then parses successive key/value pairs separated with 'sep', until either 'end' is reached or there are no characters remaining. A map of keys to values will be returned, along with the number of characters consumed. Provide 0 for start or end to indicate that there is no starting/ending delimiter. If quoteValues is true, values can be enclosed in double-quotes which will be validated by the parser and omitted from the returned map. If permitSingletons is true, keys with no values are permitted. These will result in a nil value in the returned map.

type Parser

type Parser interface {
	// Implements io.Writer. Queues the given bytes to be parsed.
	// If the parser has terminated due to a previous fatal error, it will return n=0 and an appropriate error.
	// Otherwise, it will return n=len(p) and err=nil.
	// Note that err=nil does not indicate that the data provided is valid - simply that the data was successfully queued for parsing.
	Write(p []byte) (n int, err error)
	// Register a custom header parser for a particular header type.
	// This will overwrite any existing registered parser for that header type.
	// If a parser is not available for a header type in a message, the parser will produce a core.GenericHeader struct.
	SetHeaderParser(headerName string, headerParser HeaderParser)

	Stop()

	String() string
	// Reset resets parser state
	Reset()

	ParseHeader(headerText string) (headers []Header, err error)
}

A Parser converts the raw bytes of SIP messages into core.Message objects. It allows

type Port

type Port uint16

Port number

func NewPort

func NewPort(port int) *Port

NewPort NewPort

func ParseHostPort

func ParseHostPort(rawText string) (host string, port *Port, err error)

ParseHostPort a text representation of a host[:port] pair. The port may or may not be present, so we represent it with a *uint16, and return 'nil' if no port was present.

func (*Port) Clone

func (port *Port) Clone() *Port

Clone clone

func (*Port) Equals

func (port *Port) Equals(other any) bool

Equals Equals

func (*Port) String

func (port *Port) String() string

type RecordRouteHeader

type RecordRouteHeader struct {
	Addresses []*URI
}

RecordRouteHeader RecordRouteHeader

func (*RecordRouteHeader) Clone

func (route *RecordRouteHeader) Clone() Header

Clone Clone

func (*RecordRouteHeader) Equals

func (route *RecordRouteHeader) Equals(other any) bool

Equals Equals

func (*RecordRouteHeader) Name

func (route *RecordRouteHeader) Name() string

Name Name

func (*RecordRouteHeader) String

func (route *RecordRouteHeader) String() string

type Request

type Request struct {
	// contains filtered or unexported fields
}

Request Request

func NewRequest

func NewRequest(
	messID MessageID,
	method string,
	recipient *URI,
	sipVersion string,
	hdrs []Header,
	body []byte,
) *Request

NewRequest NewRequest

func NewRequestFromResponse

func NewRequestFromResponse(method string, resp *Response) *Request

NewRequestFromResponse 基于 SIP 响应构造同一对话内的后续请求(ACK/BYE/INFO 等)。 防御性处理:Response 可能来自异常设备,缺少 Contact/Via/CSeq 等必选头部时不 panic, 用 To 地址兜底或跳过对应字段,确保 logout 等清理路径不会因残缺响应导致进程崩溃。

func (*Request) Body

func (msg *Request) Body() []byte

Body Body

func (*Request) Clone

func (req *Request) Clone() Message

Clone Clone

func (*Request) Destination

func (req *Request) Destination() net.Addr

Destination Destination

func (*Request) GetConnection

func (req *Request) GetConnection() Connection

func (*Request) IsAck

func (req *Request) IsAck() bool

IsAck IsAck

func (*Request) IsCancel

func (req *Request) IsCancel() bool

IsCancel IsCancel

func (*Request) IsInvite

func (req *Request) IsInvite() bool

IsInvite IsInvite

func (*Request) MessageID

func (msg *Request) MessageID() MessageID

MessageID MessageID

func (*Request) Method

func (req *Request) Method() string

Method Method

func (*Request) Recipient

func (req *Request) Recipient() *URI

Recipient Recipient

func (*Request) SetBody

func (msg *Request) SetBody(body []byte, setContentLength bool)

SetBody sets message body, calculates it length and add 'Content-Length' header.

func (*Request) SetConnection

func (req *Request) SetConnection(conn Connection)

func (*Request) SetDestination

func (req *Request) SetDestination(dest net.Addr)

SetDestination SetDestination

func (*Request) SetMethod

func (req *Request) SetMethod(method string)

SetMethod SetMethod

func (*Request) SetRecipient

func (req *Request) SetRecipient(recipient *URI)

SetRecipient SetRecipient

func (*Request) SetSipVersion

func (msg *Request) SetSipVersion(version string)

SetSipVersion SetSipVersion

func (*Request) SetSource

func (req *Request) SetSource(src net.Addr)

SetSource SetSource

func (*Request) SipVersion

func (msg *Request) SipVersion() string

SipVersion SipVersion

func (*Request) Source

func (req *Request) Source() net.Addr

Source Source

func (*Request) StartLine

func (req *Request) StartLine() string

StartLine returns Request Line - RFC 2361 7.1.

func (*Request) String

func (msg *Request) String() string

func (*Request) Transport

func (msg *Request) Transport() string

Transport Transport

type Response

type Response struct {
	// contains filtered or unexported fields
}

Response Response

func NewResponse

func NewResponse(
	messID MessageID,
	sipVersion string,
	statusCode int,
	reason string,
	hdrs []Header,
	body []byte,
) *Response

NewResponse NewResponse

func NewResponseFromRequest

func NewResponseFromRequest(
	resID MessageID,
	req *Request,
	statusCode int,
	reason string,
	body []byte,
) *Response

NewResponseFromRequest NewResponseFromRequest

func (*Response) Body

func (msg *Response) Body() []byte

Body Body

func (*Response) Clone

func (res *Response) Clone() Message

Clone Clone

func (*Response) Destination

func (msg *Response) Destination() net.Addr

Destination Destination

func (*Response) IsAck

func (res *Response) IsAck() bool

IsAck IsAck

func (*Response) IsCancel

func (res *Response) IsCancel() bool

IsCancel IsCancel

func (*Response) MessageID

func (msg *Response) MessageID() MessageID

MessageID MessageID

func (*Response) Reason

func (res *Response) Reason() string

Reason Reason

func (*Response) SetBody

func (msg *Response) SetBody(body []byte, setContentLength bool)

SetBody sets message body, calculates it length and add 'Content-Length' header.

func (*Response) SetConnection

func (msg *Response) SetConnection(conn Connection)

func (*Response) SetDestination

func (msg *Response) SetDestination(dest net.Addr)

SetDestination SetDestination

func (*Response) SetReason

func (res *Response) SetReason(reason string)

SetReason SetReason

func (*Response) SetSipVersion

func (msg *Response) SetSipVersion(version string)

SetSipVersion SetSipVersion

func (*Response) SetSource

func (msg *Response) SetSource(src net.Addr)

SetSource SetSource

func (*Response) SetStatusCode

func (res *Response) SetStatusCode(code int)

SetStatusCode SetStatusCode

func (*Response) SipVersion

func (msg *Response) SipVersion() string

SipVersion SipVersion

func (*Response) Source

func (msg *Response) Source() net.Addr

Source Source

func (*Response) StartLine

func (res *Response) StartLine() string

StartLine returns Response Status Line - RFC 2361 7.2.

func (*Response) StatusCode

func (res *Response) StatusCode() int

StatusCode StatusCode

func (*Response) String

func (msg *Response) String() string

func (*Response) Transport

func (msg *Response) Transport() string

Transport Transport

type RouteGroup

type RouteGroup struct {
	// contains filtered or unexported fields
}

func (*RouteGroup) Handle

func (g *RouteGroup) Handle(pattern string, handler ...HandlerFunc)

func (*RouteGroup) Use added in v1.3.34

func (g *RouteGroup) Use(middleware ...HandlerFunc) *RouteGroup

Use 注册组级中间件,仅对该分组下的路由生效

type RouteHeader

type RouteHeader struct {
	Addresses []*URI
}

RouteHeader RouteHeader

func (*RouteHeader) Clone

func (route *RouteHeader) Clone() Header

Clone Clone

func (*RouteHeader) Equals

func (route *RouteHeader) Equals(other any) bool

Equals Equals

func (*RouteHeader) Name

func (route *RouteHeader) Name() string

Name Name

func (*RouteHeader) String

func (route *RouteHeader) String() string

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server sip

func NewServer

func NewServer(form *Address) *Server

NewServer sip server

func (*Server) Close

func (s *Server) Close()

func (*Server) ListenTCPServer

func (s *Server) ListenTCPServer(addr string)

ListenTCPServer 启动 TCP 服务器并监听指定地址。

func (*Server) ListenUDPServer

func (s *Server) ListenUDPServer(addr string)

ListenUDPServer ListenUDPServer

func (*Server) Message

func (s *Server) Message(handler ...HandlerFunc) *RouteGroup

func (*Server) Notify

func (s *Server) Notify(handler ...HandlerFunc) *RouteGroup

func (*Server) ProcessTcpConn

func (s *Server) ProcessTcpConn(conn net.Conn)

ProcessTcpConn 处理传入的 TCP 连接。

func (*Server) Register

func (s *Server) Register(handler ...HandlerFunc)

func (*Server) Request

func (s *Server) Request(req *Request) (*Transaction, error)

Request Request

func (*Server) SetFrom added in v1.3.0

func (s *Server) SetFrom(from *Address)

SetFrom 热更新 SIP 源地址配置,用于配置变更时无需重启服务

func (*Server) UDPConn

func (s *Server) UDPConn() Connection

func (*Server) Use added in v1.3.34

func (s *Server) Use(middleware ...HandlerFunc)

Use 注册全局中间件,所有路由 handler 执行前先经过这些中间件; 中间件内调用 ctx.Abort() 可中断后续链路

type String

type String struct {
	Str string
}

String string

func (String) Equals

func (str String) Equals(other any) bool

Equals Equals

func (String) String

func (str String) String() string

type Subject added in v1.3.34

type Subject string

Subject SIP Subject 头

func (Subject) Clone added in v1.3.34

func (ct Subject) Clone() Header

func (*Subject) Equals added in v1.3.34

func (ct *Subject) Equals(other any) bool

func (*Subject) Name added in v1.3.34

func (ct *Subject) Name() string

func (Subject) String added in v1.3.34

func (ct Subject) String() string

type SupportedHeader

type SupportedHeader struct {
	Options []string
}

SupportedHeader SupportedHeader

func (*SupportedHeader) Clone

func (support *SupportedHeader) Clone() Header

Clone clone

func (*SupportedHeader) Equals

func (support *SupportedHeader) Equals(other any) bool

Equals Equals

func (*SupportedHeader) Name

func (support *SupportedHeader) Name() string

Name name

func (*SupportedHeader) String

func (support *SupportedHeader) String() string

type ToHeader

type ToHeader struct {
	// The display name from the header, may be omitted.
	DisplayName MaybeString
	Address     *URI
	// Any parameters present in the header.
	Params Params
}

ToHeader introduces SIP 'To' header

func (*ToHeader) Clone

func (to *ToHeader) Clone() Header

Clone Copy the header.

func (*ToHeader) Equals

func (to *ToHeader) Equals(other any) bool

Equals Equals

func (*ToHeader) Name

func (to *ToHeader) Name() string

Name Name

func (*ToHeader) String

func (to *ToHeader) String() string

type Transaction

type Transaction struct {
	// contains filtered or unexported fields
}

Transaction Transaction

func NewTransaction

func NewTransaction(key string, conn Connection) *Transaction

NewTransaction NewTransaction

func (*Transaction) Close

func (tx *Transaction) Close()

Close Close

func (*Transaction) GetResponse

func (tx *Transaction) GetResponse() *Response

GetResponse GetResponse

func (*Transaction) Key

func (tx *Transaction) Key() string

Key Key

func (*Transaction) Request

func (tx *Transaction) Request(req *Request) error

Request Request

func (*Transaction) Respond

func (tx *Transaction) Respond(res *Response) error

Respond Respond

type URI

type URI struct {
	// True if and only if the URI is a SIPS URI.
	FIsEncrypted 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'.
	FUser MaybeString

	// 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.
	// This is a pointer, so that URIs without a password field can have 'nil'.
	// Note that RFC 3261 strongly recommends against the use of password fields in SIP URIs,
	// as they are fundamentally insecure.
	FPassword MaybeString

	// The host part of the URI. This can be a domain, or a string representation of an IP address.
	FHost string

	// The port part of the URI. This is optional, and so is represented here as a pointer type.
	FPort *Port

	// 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.
	FUriParams Params

	// 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 '?'.
	// Although the values of the map are MaybeStrings, they will never be NoString in practice as the parser
	// guarantees to not return blank values for header elements in SIP URIs.
	// You should not set the values of headers to NoString.
	FHeaders Params
}

URI A SIP or SIPS URI, including all params and URI header params. noinspection GoNameStartsWithPackageName

func ParseRequestLine

func ParseRequestLine(requestLine string) (
	method string, recipient *URI, sipVersion string, err error,
)

ParseRequestLine the first line of a SIP request, e.g:

INVITE bob@example.com SIP/2.0
REGISTER jane@telco.com SIP/1.0

func ParseSipURI

func ParseSipURI(uriStr string) (uri URI, err error)

ParseSipURI converts a string representation of a SIP or SIPS URI into a SipURI object.

func ParseURI

func ParseURI(uriStr string) (uri *URI, err error)

ParseURI converts a string representation of a URI into a Uri object. If the URI is malformed, or the URI schema is not recognised, an error is returned. URIs have the general form of schema:address.

func (*URI) Clone

func (uri *URI) Clone() *URI

Clone the Sip URI.

func (*URI) Equals

func (uri *URI) Equals(val any) bool

Equals Determine if the SIP URI is equal to the specified URI according to the rules laid down in RFC 3261 s. 19.1.4. TODO: The Equals method is not currently RFC-compliant; fix this!

func (*URI) Host

func (uri *URI) Host() string

Host Host

func (*URI) SetHost

func (uri *URI) SetHost(host string)

SetHost SetHost

func (*URI) String

func (uri *URI) String() string

Generates the string representation of a SipUri struct.

func (*URI) User

func (uri *URI) User() MaybeString

User User

type UserAgentHeader

type UserAgentHeader string

UserAgentHeader UserAgentHeader

func (*UserAgentHeader) Clone

func (ua *UserAgentHeader) Clone() Header

Clone clone

func (*UserAgentHeader) Equals

func (ua *UserAgentHeader) Equals(other any) bool

Equals equals

func (*UserAgentHeader) Name

func (ua *UserAgentHeader) Name() string

Name Name

func (UserAgentHeader) String

func (ua UserAgentHeader) String() string

type ViaHeader

type ViaHeader []*ViaHop

ViaHeader ViaHeader

func (ViaHeader) Clone

func (via ViaHeader) Clone() Header

Clone Clone

func (ViaHeader) Equals

func (via ViaHeader) Equals(other any) bool

Equals Equals

func (ViaHeader) Name

func (via ViaHeader) Name() string

Name Name

func (ViaHeader) String

func (via ViaHeader) String() string

type ViaHop

type ViaHop struct {
	// E.g. 'SIP'.
	ProtocolName string
	// E.g. '2.0'.
	ProtocolVersion string
	Transport       string
	Host            string
	// The port for this via hop. This is stored as a pointer type, since it is an optional field.
	Port   *Port
	Params Params
}

ViaHop A single component in a Via header. Via headers are composed of several segments of the same structure, added by successive nodes in a routing chain.

func (*ViaHop) Clone

func (hop *ViaHop) Clone() *ViaHop

Clone Return an exact copy of this ViaHop.

func (*ViaHop) Equals

func (hop *ViaHop) Equals(other any) bool

Equals Equals

func (*ViaHop) SentBy

func (hop *ViaHop) SentBy() string

SentBy SentBy

func (*ViaHop) String

func (hop *ViaHop) String() string

type XGBVer

type XGBVer string

func (XGBVer) Clone

func (ct XGBVer) Clone() Header

Clone Clone

func (*XGBVer) Equals

func (ct *XGBVer) Equals(other any) bool

Equals Equals

func (XGBVer) Name

func (ct XGBVer) Name() string

Name Name

func (XGBVer) String

func (ct XGBVer) String() string

Jump to

Keyboard shortcuts

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