Documentation ¶
Index ¶
- Constants
- Variables
- func BuildAlarmResponseXML(id string) string
- func BuildCatalogXML(sn int, id string) string
- func BuildDeviceInfoXML(sn int, id string) string
- func BuildRecordInfoXML(sn int, id string, start, end int64) string
- func DemoMessage()
- func DemoVIA()
- func DumpError(code int) string
- func Encode(msg *Message) ([]byte, error)
- func RandBranch() string
- type Authorization
- type CSeq
- type Contact
- type Message
- func (m *Message) BuildOK() *Message
- func (m *Message) BuildResponse(code int) *Message
- func (m *Message) BuildResponseWithPhrase(code int, phrase string) *Message
- func (m *Message) Destination() string
- func (m *Message) GetBranch() string
- func (m *Message) GetMethod() Method
- func (m *Message) GetMode() Mode
- func (m *Message) GetReason() string
- func (m *Message) GetStatusCode() int
- func (m *Message) IsReliable() bool
- func (m *Message) IsRequest() bool
- func (m *Message) IsResponse() bool
- func (m *Message) Source() string
- type Method
- type Mode
- type Request
- type Response
- type StartLine
- type URI
- type Via
- type WwwAuthenticate
Constants ¶
const ( MESSAGE_CATALOG = "Catalog" MESSAGE_DEVICE_INFO = "DeviceInfo" MESSAGE_BROADCAST = "Broadcast" MESSAGE_DEVICE_STATUS = "DeviceStatus" MESSAGE_KEEP_ALIVE = "Keepalive" MESSAGE_MOBILE_POSITION = "MobilePosition" MESSAGE_MOBILE_POSITION_INTERVAL = "Interval" ELEMENT_DEVICE_ID = "DeviceID" ELEMENT_DEVICE_LIST = "DeviceList" ELEMENT_NAME = "Name" ELEMENT_STATUS = "Status" )
sip message body xml解析的字段
const ( VERSION = "SIP/2.0" // sip version CRLF = "\r\n" // 0x0D0A CRLFCRLF = "\r\n\r\n" // 0x0D0A0D0A DIGEST_ALGO_MD5 = "MD5" )
换行符号: linux,unix : \r\n windows : \n Mac OS : \r
Variables ¶
var ( // CatalogXML 获取设备列表xml样式 CatalogXML = `<?xml version="1.0"?><Query> <CmdType>Catalog</CmdType> <SN>%d</SN> <DeviceID>%s</DeviceID> </Query> ` // RecordInfoXML 获取录像文件列表xml样式 RecordInfoXML = `` /* 192-byte string literal not displayed */ // DeviceInfoXML 查询设备详情xml样式 DeviceInfoXML = `<?xml version="1.0"?> <Query> <CmdType>DeviceInfo</CmdType> <SN>%d</SN> <DeviceID>%s</DeviceID> </Query> ` )
var (
AlarmResponseXML = `<?xml version="1.0"?>
<Response>
<CmdType>Alarm</CmdType>
<SN>17430</SN>
<DeviceID>%s</DeviceID>
</Response>
`
)
AlarmResponseXML alarm response xml样式
Functions ¶
func BuildAlarmResponseXML ¶ added in v3.0.4
BuildRecordInfoXML 获取录像文件列表指令
func BuildCatalogXML ¶ added in v3.0.4
BuildCatalogXML 获取NVR下设备列表指令
func BuildDeviceInfoXML ¶ added in v3.0.4
BuildDeviceInfoXML 获取设备详情指令
func BuildRecordInfoXML ¶ added in v3.0.4
BuildRecordInfoXML 获取录像文件列表指令
func DemoMessage ¶
func DemoMessage()
Types ¶
type Authorization ¶
type Authorization struct {
// contains filtered or unexported fields
}
func (*Authorization) GetUsername ¶
func (a *Authorization) GetUsername() string
func (*Authorization) Parse ¶
func (a *Authorization) Parse(str string) error
func (*Authorization) String ¶
func (a *Authorization) String() string
Authorization: Digest username="admin", realm="hik", nonce="a8afe6fcbee6331d89d3eb0d3d19ce39", uri="sip:130909115229300920@10.64.49.44:7100", response="907ddb1bcc25174d7de4a96c947fb066", algorithm=MD5, opaque="a853e4f25298413f"
func (*Authorization) Verify ¶
func (a *Authorization) Verify(username, passwd, realm, nonce string) bool
type Contact ¶
type Contact struct { Nickname string //可以没有 Uri URI // //header params Params map[string]string // include tag/q/expires // contains filtered or unexported fields }
To From Referto Contact From: <sip:34020000001320000001@3402000000>;tag=575945878 To: <sip:34020000002000000001@3402000000> Contact: <sip:34020000001320000001@27.38.49.149:49243> Contact: <sip:34020000001320000001@192.168.1.64:5060>;expires=0
type Message ¶
type Message struct { Mode Mode //0:REQUEST, 1:RESPONSE StartLine *StartLine Via *Via //Via From *Contact //From To *Contact //To CallID string //Call-ID CSeq *CSeq //CSeq Contact *Contact //Contact Authorization *Authorization //Authorization MaxForwards int //Max-Forwards UserAgent string //User-Agent Subject string //Subject ContentType string //Content-Type Expires int //Expires ContentLength int //Content-Length Route *Contact Body string Addr string Event string Date time.Time WwwAuthenticate *WwwAuthenticate //gb28181 密码验证 上级发给下级是WwwAuthenticate;下级发给上级是Authorization SourceAdd net.Addr DestAdd net.Addr }
func BuildMessageRequest ¶
func (*Message) BuildResponse ¶
func (*Message) BuildResponseWithPhrase ¶
func (*Message) Destination ¶
目标地址:这个应该是用于通过route头域实现proxy这样的功能,暂时不支持
func (*Message) IsResponse ¶
type Method ¶
type Method string
sip request method
const ( ACK Method = "ACK" BYE Method = "BYE" CANCEL Method = "CANCEL" INVITE Method = "INVITE" OPTIONS Method = "OPTIONS" REGISTER Method = "REGISTER" NOTIFY Method = "NOTIFY" SUBSCRIBE Method = "SUBSCRIBE" MESSAGE Method = "MESSAGE" REFER Method = "REFER" INFO Method = "INFO" PRACK Method = "PRACK" UPDATE Method = "UPDATE" PUBLISH Method = "PUBLISH" )
type StartLine ¶
type StartLine struct { //request line: method uri version Method Method Uri URI //Request-URI:请求的服务地址,不能包含空白字符或者控制字符,并且禁止用”<>”括上。 Version string //status line: version code phrase Code int //status code // contains filtered or unexported fields }
startline MESSAGE sip:34020000001320000001@3402000000 SIP/2.0 SIP/2.0 200 OK
type URI ¶
type URI struct {
// contains filtered or unexported fields
}
RFC3261 SIP-URI = "sip:" [ userinfo ] hostport
uri-parameters [ headers ]
SIPS-URI = "sips:" [ userinfo ] hostport
uri-parameters [ headers ]
userinfo = ( user / telephone-subscriber ) [ ":" password ] "@" user = 1*( unreserved / escaped / user-unreserved ) user-unreserved = "&" / "=" / "+" / "$" / "," / ";" / "?" / "/" password = *( unreserved / escaped /
"&" / "=" / "+" / "$" / "," )
hostport = host [ ":" port ] host = hostname / IPv4address / IPv6reference hostname = *( domainlabel "." ) toplabel [ "." ] domainlabel = alphanum
/ alphanum *( alphanum / "-" ) alphanum
toplabel = ALPHA / ALPHA *( alphanum / "-" ) alphanum
IPv4address = 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT IPv6reference = "[" IPv6address "]" IPv6address = hexpart [ ":" IPv4address ] hexpart = hexseq / hexseq "::" [ hexseq ] / "::" [ hexseq ] hexseq = hex4 *( ":" hex4) hex4 = 1*4HEXDIG port = 1*DIGIT
uri-parameters = *( ";" uri-parameter) uri-parameter = transport-param / user-param / method-param
/ ttl-param / maddr-param / lr-param / other-param
transport-param = "transport="
( "udp" / "tcp" / "sctp" / "tls" / other-transport)
other-transport = token user-param = "user=" ( "phone" / "ip" / other-user) other-user = token method-param = "method=" Method ttl-param = "ttl=" ttl maddr-param = "maddr=" host lr-param = "lr" other-param = pname [ "=" pvalue ] pname = 1*paramchar pvalue = 1*paramchar paramchar = param-unreserved / unreserved / escaped param-unreserved = "[" / "]" / "/" / ":" / "&" / "+" / "$"
headers = "?" header *( "&" header ) header = hname "=" hvalue hname = 1*( hnv-unreserved / unreserved / escaped ) hvalue = *( hnv-unreserved / unreserved / escaped ) hnv-unreserved = "[" / "]" / "/" / "?" / ":" / "+" / "$"
type Via ¶
type Via struct { Version string // sip version: default to SIP/2.0 Transport string // UDP,TCP ,TLS , SCTP Host string // sent-by : host:port Port string // //header params Params map[string]string // include branch/rport/received/ttl/maddr // contains filtered or unexported fields }
Via = ( "Via" / "v" ) HCOLON via-parm *(COMMA via-parm) via-parm = sent-protocol LWS sent-by *( SEMI via-params ) via-params = via-ttl / via-maddr
/ via-received / via-branch / via-extension
via-ttl = "ttl" EQUAL ttl via-maddr = "maddr" EQUAL host via-received = "received" EQUAL (IPv4address / IPv6address) via-branch = "branch" EQUAL token via-extension = generic-param sent-protocol = protocol-name SLASH protocol-version
SLASH transport
protocol-name = "SIP" / token protocol-version = token transport = "UDP" / "TCP" / "TLS" / "SCTP"
/ other-transport
sent-by = host [ COLON port ] ttl = 1*3DIGIT ; 0 to 255
type WwwAuthenticate ¶
type WwwAuthenticate struct {
// contains filtered or unexported fields
}
func NewWwwAuthenticate ¶
func NewWwwAuthenticate(realm, nonce, algorithm string) *WwwAuthenticate
func (*WwwAuthenticate) Parse ¶
func (w *WwwAuthenticate) Parse(str string) error
func (*WwwAuthenticate) String ¶
func (w *WwwAuthenticate) String() string
WWW-Authenticate: Digest realm="hik", nonce="a8afe6fcbee6331d89d3eb0d3d19ce39", opaque="a853e4f25298413f9bf3a9aa6767857d", algorithm=MD5