Documentation
¶
Index ¶
- Constants
- Variables
- func CalcResponse(username, realm, password, method, uri, nonce, qop, cnonce, nc string) string
- func CopyHeaders(name string, from, to Message)
- func GbkToUtf8(s []byte) ([]byte, error)
- func GenerateBranch() string
- func GetCatalogXML(id string) []byte
- func GetDeviceInfoXML(id string) []byte
- func GetRecordInfoXML(id string, sceqNo int, start, end int64) []byte
- func GetRequest(url string) ([]byte, error)
- func JSONDecode(data []byte, obj any) error
- func JSONEncode(data any) []byte
- func Max(a, b int64) int64
- func NewError(err error, params ...any) error
- func ParseAddressValue(addressText string) (displayName MaybeString, uri *URI, headerParams Params, err error)
- func ParseAddressValues(addresses string) (displayNames []MaybeString, uris []*URI, headerParams []Params, err error)
- func ParseStatusLine(statusLine string) (sipVersion string, statusCode int, reasonPhrase string, err error)
- func PostJSONRequest(url string, data any) ([]byte, error)
- func PostRequest(url string, bodyType string, body io.Reader) ([]byte, error)
- func RandInt(min, max int) int
- func RandString(n int) string
- func ResolveSelfIP() (net.IP, error)
- func SplitByWhitespace(text string) []string
- func Uint16PtrEq(a *uint16, b *uint16) bool
- func Utf8ToGbk(s []byte) ([]byte, error)
- func XMLDecode(data []byte, v any) error
- func XMLEncode(data any) ([]byte, error)
- type Accept
- type Address
- type AllowHeader
- type Authorization
- func (auth *Authorization) CalcResponse() string
- func (auth *Authorization) Get(key string) string
- func (auth *Authorization) SetMethod(method string) *Authorization
- func (auth *Authorization) SetPassword(password string) *Authorization
- func (auth *Authorization) SetURI(uri string) *Authorization
- func (auth *Authorization) SetUsername(username string) *Authorization
- func (auth *Authorization) String() string
- type CSeq
- type CallID
- type Collector
- type CollectorMsg
- type Connection
- type ContactHeader
- type Content
- type ContentLength
- type ContentType
- type Context
- func (c *Context) Abort()
- func (c *Context) AbortString(status int, msg string)
- func (c *Context) Get(k string) (any, bool)
- func (c *Context) GetHeader(key string) string
- func (c *Context) GetMustInt(k string) int
- func (c *Context) GetMustString(k string) string
- func (c *Context) IsAborted() bool
- func (c *Context) Next()
- func (c *Context) SendRequest(method string, body []byte) (*Transaction, error)
- func (c *Context) Set(k string, v any)
- func (c *Context) String(status int, msg string)
- type Error
- type Expires
- type FromHeader
- type GenericHeader
- type HandlerFunc
- type Header
- type HeaderParser
- type HeadersBuilder
- func (hb *HeadersBuilder) AddVia(via *ViaHop) *HeadersBuilder
- func (hb *HeadersBuilder) Build() []Header
- func (hb *HeadersBuilder) SetCallID(callID *CallID) *HeadersBuilder
- func (hb *HeadersBuilder) SetContact(address *Address) *HeadersBuilder
- func (hb *HeadersBuilder) SetContentType(contentType *ContentType) *HeadersBuilder
- func (hb *HeadersBuilder) SetFrom(address *Address) *HeadersBuilder
- func (hb *HeadersBuilder) SetMethod(method string) *HeadersBuilder
- func (hb *HeadersBuilder) SetSeqNo(seqNo uint) *HeadersBuilder
- func (hb *HeadersBuilder) SetSubject(v string) *HeadersBuilder
- func (hb *HeadersBuilder) SetTo(address *Address) *HeadersBuilder
- func (hb *HeadersBuilder) SetToWithParam(address *Address) *HeadersBuilder
- func (hb *HeadersBuilder) SetXGBVer() *HeadersBuilder
- type MaxForwards
- type MaybeString
- type Message
- type MessageID
- type MessageReceive
- type NoRepeatFn
- type Observer
- type ObserverHandler
- type Packet
- type Params
- type Parser
- type Port
- type RecordRouteHeader
- type Request
- func (msg *Request) Body() []byte
- func (req *Request) Clone() Message
- func (req *Request) Destination() net.Addr
- func (req *Request) GetConnection() Connection
- func (req *Request) IsAck() bool
- func (req *Request) IsCancel() bool
- func (req *Request) IsInvite() bool
- func (msg *Request) MessageID() MessageID
- func (req *Request) Method() string
- func (req *Request) Recipient() *URI
- func (msg *Request) SetBody(body []byte, setContentLength bool)
- func (req *Request) SetConnection(conn Connection)
- func (req *Request) SetDestination(dest net.Addr)
- func (req *Request) SetMethod(method string)
- func (req *Request) SetRecipient(recipient *URI)
- func (msg *Request) SetSipVersion(version string)
- func (req *Request) SetSource(src net.Addr)
- func (msg *Request) SipVersion() string
- func (req *Request) Source() net.Addr
- func (req *Request) StartLine() string
- func (msg *Request) String() string
- func (msg *Request) Transport() string
- type Response
- func (msg *Response) Body() []byte
- func (res *Response) Clone() Message
- func (msg *Response) Destination() net.Addr
- func (res *Response) IsAck() bool
- func (res *Response) IsCancel() bool
- func (msg *Response) MessageID() MessageID
- func (res *Response) Reason() string
- func (msg *Response) SetBody(body []byte, setContentLength bool)
- func (msg *Response) SetConnection(conn Connection)
- func (msg *Response) SetDestination(dest net.Addr)
- func (res *Response) SetReason(reason string)
- func (msg *Response) SetSipVersion(version string)
- func (msg *Response) SetSource(src net.Addr)
- func (res *Response) SetStatusCode(code int)
- func (msg *Response) SipVersion() string
- func (msg *Response) Source() net.Addr
- func (res *Response) StartLine() string
- func (res *Response) StatusCode() int
- func (msg *Response) String() string
- func (msg *Response) Transport() string
- type RouteGroup
- type RouteHeader
- type Server
- func (s *Server) Close()
- func (s *Server) ListenTCPServer(addr string)
- func (s *Server) ListenUDPServer(addr string)
- func (s *Server) Message(handler ...HandlerFunc) *RouteGroup
- func (s *Server) Notify(handler ...HandlerFunc) *RouteGroup
- func (s *Server) ProcessTcpConn(conn net.Conn)
- func (s *Server) Register(handler ...HandlerFunc)
- func (s *Server) Request(req *Request) (*Transaction, error)
- func (s *Server) SetFrom(from *Address)
- func (s *Server) UDPConn() Connection
- func (s *Server) Use(middleware ...HandlerFunc)
- type String
- type Subject
- type SupportedHeader
- type ToHeader
- type Transaction
- type URI
- type UserAgentHeader
- type ViaHeader
- type ViaHop
- type XGBVer
Constants ¶
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.
const RFC3261BranchMagicCookie = "z9hG4bK"
RFC3261BranchMagicCookie RFC3261BranchMagicCookie
Variables ¶
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> ` )
var ContentTypeSDP = ContentType("APPLICATION/SDP")
ContentTypeSDP SDP contenttype
var ContentTypeXML = ContentType("Application/MANSCDP+xml")
ContentTypeXML XML contenttype
var DefaultProtocol = "udp"
DefaultProtocol DefaultProtocol
var DefaultSipVersion = "SIP/2.0"
DefaultSipVersion DefaultSipVersion
Functions ¶
func CalcResponse ¶
CalcResponse Authorization response https://www.ietf.org/rfc/rfc2617.txt
func CopyHeaders ¶
CopyHeaders Copy all headers of one type from one message to another. Appending to any headers that were already there.
func GetRecordInfoXML ¶
GetRecordInfoXML 获取录像文件列表指令
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 ¶
PostJSONRequest PostJSONRequest
func PostRequest ¶
PostRequest PostRequest
func RandString ¶
func SplitByWhitespace ¶
SplitByWhitespace Splits the given string into sections, separated by one or more characters from c_ABNF_WS.
func Uint16PtrEq ¶
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.
Types ¶
type Address ¶
type Address struct {
DisplayName MaybeString
URI *URI
Params Params
}
Address Address
func NewAddressFromFromHeader ¶
func NewAddressFromFromHeader(from *FromHeader) *Address
NewAddressFromFromHeader NewAddressFromFromHeader
type AllowHeader ¶
type AllowHeader []string
AllowHeader AllowHeader
func (AllowHeader) String ¶
func (allow AllowHeader) String() string
type Authorization ¶
Authorization currently only Digest and MD5
func (*Authorization) CalcResponse ¶
func (auth *Authorization) CalcResponse() string
CalcResponse CalcResponse
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 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]) Write ¶
func (c *Collector[T]) Write(info *CollectorMsg[T])
type CollectorMsg ¶
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) String ¶
func (contact *ContactHeader) String() string
type ContentLength ¶
type ContentLength uint32
ContentLength ContentLength header
func (*ContentLength) Equals ¶
func (contentLength *ContentLength) Equals(other any) bool
Equals Equals
func (ContentLength) String ¶
func (contentLength ContentLength) String() string
type ContentType ¶
type ContentType string
ContentType ContentType
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) AbortString ¶
func (*Context) GetMustInt ¶
func (*Context) GetMustString ¶
func (*Context) SendRequest ¶
func (c *Context) SendRequest(method string, body []byte) (*Transaction, error)
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) 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) 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 ¶
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 ¶
ParseHeader ParseHeader
type HeaderParser ¶
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 (*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) String ¶
func (maxForwards MaxForwards) String() string
type MaybeString ¶
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 MessageReceive ¶
type NoRepeatFn ¶
type Observer ¶
type Observer struct {
// contains filtered or unexported fields
}
Observer 观察者
func (*Observer) DefaultRegister ¶
DefaultRegister 默认的注册行为
type ObserverHandler ¶
ObserverHandler 返回 true 表示完成任务
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 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 ParseHostPort ¶
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.
type RecordRouteHeader ¶
type RecordRouteHeader struct {
Addresses []*URI
}
RecordRouteHeader RecordRouteHeader
func (*RecordRouteHeader) Equals ¶
func (route *RecordRouteHeader) Equals(other any) bool
Equals Equals
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 ¶
NewRequestFromResponse 基于 SIP 响应构造同一对话内的后续请求(ACK/BYE/INFO 等)。 防御性处理:Response 可能来自异常设备,缺少 Contact/Via/CSeq 等必选头部时不 panic, 用 To 地址兜底或跳过对应字段,确保 logout 等清理路径不会因残缺响应导致进程崩溃。
func (*Request) GetConnection ¶
func (req *Request) GetConnection() Connection
func (*Request) SetBody ¶
SetBody sets message body, calculates it length and add 'Content-Length' header.
func (*Request) SetConnection ¶
func (req *Request) SetConnection(conn Connection)
func (*Request) SetDestination ¶
SetDestination SetDestination
func (*Request) SetRecipient ¶
SetRecipient SetRecipient
func (*Request) SetSipVersion ¶
func (msg *Request) SetSipVersion(version string)
SetSipVersion SetSipVersion
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) SetBody ¶
SetBody sets message body, calculates it length and add 'Content-Length' header.
func (*Response) SetConnection ¶
func (msg *Response) SetConnection(conn Connection)
func (*Response) SetDestination ¶
SetDestination SetDestination
func (*Response) SetSipVersion ¶
func (msg *Response) SetSipVersion(version string)
SetSipVersion SetSipVersion
func (*Response) SetStatusCode ¶
SetStatusCode SetStatusCode
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) String ¶
func (route *RouteHeader) String() string
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server sip
func (*Server) ListenTCPServer ¶
ListenTCPServer 启动 TCP 服务器并监听指定地址。
func (*Server) ListenUDPServer ¶
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 ¶
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) 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 SupportedHeader ¶
type SupportedHeader struct {
Options []string
}
SupportedHeader SupportedHeader
func (*SupportedHeader) Equals ¶
func (support *SupportedHeader) Equals(other any) bool
Equals Equals
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
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) GetResponse ¶
func (tx *Transaction) GetResponse() *Response
GetResponse GetResponse
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 ¶
ParseSipURI converts a string representation of a SIP or SIPS URI into a SipURI object.
func ParseURI ¶
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) Equals ¶
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!
type UserAgentHeader ¶
type UserAgentHeader string
UserAgentHeader UserAgentHeader
func (UserAgentHeader) String ¶
func (ua UserAgentHeader) 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.