Documentation ¶
Index ¶
- Constants
- Variables
- func BuildAlarmResponseXML(id string) string
- func BuildCatalogXML(sn int, id string) string
- func BuildDeviceInfoXML(sn int, id string) string
- func BuildDeviceStatusXml(sn int, id string) string
- func BuildKeepLvieXML(sn int, id string) string
- func BuildRecordInfoXML(sn int, id string, start, end int64) string
- func CreatePtzCmd(ptzType PTZ_Cmd_type, param int) string
- func DemoMessage()
- func DemoVIA()
- func DumpError(code int) string
- func Encode(msg *Message) ([]byte, error)
- func RandBranch() string
- func XmlMashal(mode interface{}) (string, error)
- type Authorization
- type CSeq
- type ChannelInfo
- type CmdCdnLiveResult
- type CmdCdnLiver
- type Contact
- type ExecType
- type LiveType
- 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 PTZ_Cmd_type
- type PtzCmdBody
- type QueryBody
- type ReponseBody
- type Request
- type Response
- type StartLine
- type URI
- type Via
- type WwwAuthenticate
- type XProtocol
Constants ¶
const ( MESSAGE_CATALOG = "Catalog" MESSAGE_DEVICE_INFO = "DeviceInfo" MESSAGE_RECORD_INFO = "RecordInfo" MESSAGE_BROADCAST = "Broadcast" MESSAGE_DEVICE_STATUS = "DeviceStatus" MESSAGE_DEVICE_CTL = "DeviceControl" MESSAGE_KEEP_ALIVE = "Keepalive" MESSAGE_ALARM = "Alarm" 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 ( LIVE_STREAM_PUSH LiveType = iota LIVE_CDN_PUSH ExecStop ExecType = iota ExecPlay )
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> ` //DeviceStatusXml 查询设备状态xml样式 DeviceStatusXml = `<?xml version="1.0"?> <Query> <CmdType>DeviceStatus</CmdType> <SN>%d</SN> <DeviceID>%s</DeviceID> </Query> ` //KeepLiveXml 心跳命令xml KeepLiveXml = `` /* 126-byte string literal not displayed */ )
var ( AlarmResponseXML = `<?xml version="1.0"?> <Response> <CmdType>Alarm</CmdType> <SN>17430</SN> <DeviceID>%s</DeviceID> </Response> ` NotifyResponseXML = `` /* 129-byte string literal not displayed */ DeviceResponseXML = `` /* 244-byte string literal not displayed */ )
AlarmResponseXML alarm response xml样式
Functions ¶
func BuildAlarmResponseXML ¶
BuildRecordInfoXML 获取录像文件列表指令
func BuildDeviceInfoXML ¶
BuildDeviceInfoXML 获取设备详情指令
func BuildDeviceStatusXml ¶ added in v1.0.3
BuildDeviceStatusXml 获取设备状态指令
func BuildKeepLvieXML ¶ added in v1.0.3
BuildKeepLvieXML 设备状态报送指令
func BuildRecordInfoXML ¶
BuildRecordInfoXML 获取录像文件列表指令
func CreatePtzCmd ¶
func CreatePtzCmd(ptzType PTZ_Cmd_type, param int) string
func DemoMessage ¶
func DemoMessage()
Types ¶
type Authorization ¶
type Authorization struct {
// contains filtered or unexported fields
}
func NewAuthorization ¶ added in v1.0.7
func NewAuthorization(username, realm, nonce, uri, pwd, algorithm string) *Authorization
func ToAuthorization ¶ added in v1.0.8
func ToAuthorization(username, uri, pwd string, authen *WwwAuthenticate) *Authorization
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 ChannelInfo ¶ added in v1.0.6
type ChannelInfo struct { DeviceID string Name string Manufacturer string Model string Owner string CivilCode string //对应行政区域代码 Block string //对应组织机构代码 符合GA/T 380-2011 Address string //设备安装地址 Parental string ParentID string //设备父级设备ID/虚拟组织 SafetyWay string RegisterWay string Secrecy uint IPAddress string Port uint16 Status string Longitude string Latitude string }
type CmdCdnLiveResult ¶ added in v1.3.3
type CmdCdnLiveResult struct { XMLName xml.Name `xml:"Reponse"` CmdType string DeviceID string SN string Result string Extends string //扩展数据 }
func (*CmdCdnLiveResult) Decode ¶ added in v1.3.4
func (r *CmdCdnLiveResult) Decode(data string) error
func (*CmdCdnLiveResult) String ¶ added in v1.3.4
func (r *CmdCdnLiveResult) String() string
type CmdCdnLiver ¶ added in v1.3.3
type CmdCdnLiver struct { XMLName xml.Name `xml:"Control"` CmdType string DeviceID string SN string LiveType LiveType //直播类型: 0:流媒体推流 1:CDN推流 ExecCmd ExecType // 执行类型: 0:stop 1:start Endtimes uint64 //结束时间 StreamId string //流ID }
func (*CmdCdnLiver) Decode ¶ added in v1.3.4
func (c *CmdCdnLiver) Decode(data string) error
func (*CmdCdnLiver) String ¶ added in v1.3.4
func (c *CmdCdnLiver) String() string
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 XProtocol XProtocol //协议类型: GB28181,PMS-SIP 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 PTZ_Cmd_type ¶
type PTZ_Cmd_type int
const ( Ptz_ctrl_halt PTZ_Cmd_type = iota //停止0 Ptz_ctrl_right //右转1 Ptz_ctrl_rightup //右上2 Ptz_ctrl_up //向上3 Ptz_ctrl_leftup //左上4 Ptz_ctrl_left //向左5 Ptz_ctrl_leftdown //左下6 Ptz_ctrl_down //向下7 Ptz_ctrl_rightdown //右下8 Ptz_ctrl_zoom //镜头放大/缩小9 Ptz_ctrl_iris //光圈放大/缩小10 Ptz_ctrl_focus //镜头聚焦/放焦11 )
type PtzCmdBody ¶ added in v1.3.4
type PtzCmdBody struct { XMLName xml.Name `xml:"Control"` CmdType string DeviceID string SN string PTZCmd string }
func (*PtzCmdBody) Decode ¶ added in v1.3.4
func (c *PtzCmdBody) Decode(data string) error
func (*PtzCmdBody) String ¶ added in v1.3.4
func (c *PtzCmdBody) String() string
type ReponseBody ¶ added in v1.0.6
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) GetAlgorithm ¶ added in v1.0.8
func (w *WwwAuthenticate) GetAlgorithm() string
func (*WwwAuthenticate) GetNonce ¶ added in v1.0.8
func (w *WwwAuthenticate) GetNonce() string
func (*WwwAuthenticate) GetRealm ¶ added in v1.0.8
func (w *WwwAuthenticate) GetRealm() string
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