代码拉取完成,页面将自动刷新
package tu
import (
"fmt"
"gitee.com/slh1992/plugin-sip/sip"
"gitee.com/slh1992/plugin-sip/utils"
"strings"
"time"
)
//根据参数构建各种消息
//参数来自于session/transaction等会话管理器
/*
method:请求方法
transport:UDP/TCP
sipSerial: sip server ID
sipRealm: sip domain
username: 用户名/设备序列号
srcIP: 源IP
srcPort:源端口
expires: 过期时间
cseq:消息序列号,当前对话递增
*/
//构建消息:以客户端(可能是IPC,也可能是SIP Server)的角度
func BuildMessageRequest(method sip.Method, transport, sipSerial, sipRealm, username, srcIP string, srcPort uint16, expires, cseq int, body string) *sip.Message {
server := fmt.Sprintf("%s@%s", sipSerial, sipRealm)
client := fmt.Sprintf("%s@%s", username, sipRealm)
msg := &sip.Message{
Mode: sip.SIP_MESSAGE_REQUEST,
MaxForwards: 70,
UserAgent: "IPC",
Expires: expires,
ContentLength: 0,
}
msg.StartLine = &sip.StartLine{
Method: method,
Uri: sip.NewURI(server),
}
msg.Via = &sip.Via{
Transport: transport,
Host: fmt.Sprintf("%s:%d", srcIP, srcPort),
}
msg.Via.Params = map[string]string{
"branch": randBranch(),
"rport": "-1", //only key,no-value
}
msg.From = &sip.Contact{
Uri: sip.NewURI(client),
Params: nil,
}
msg.From.Params = map[string]string{
"tag": utils.RandNumString(10),
}
msg.To = &sip.Contact{
Uri: sip.NewURI(client),
}
msg.CallID = utils.RandNumString(8)
msg.CSeq = &sip.CSeq{
ID: uint32(cseq),
Method: method,
}
msg.Contact = &sip.Contact{
Uri: sip.NewURI(fmt.Sprintf("%s@%s:%d", username, srcIP, srcPort)),
}
if len(body) > 0 {
msg.ContentLength = len(body)
msg.Body = body
}
msg.Date = time.Now()
return msg
}
//根据参数构建各种消息
//参数来自于session/transaction等会话管理器
/*
method:请求方法
transport:UDP/TCP
sipSerial: sip server ID
sipRealm: sip domain
username: 用户名/设备序列号
srcIP: 源IP
srcPort:源端口
expires: 过期时间
cseq:消息序列号,当前对话递增
*/
//构建消息:以客户端(可能是IPC,也可能是SIP Server)的角度
func BuildClientMessageRequest(method sip.Method, transport, sipSerial, sipRealm, username, srcIP string, srcPort uint16, expires, cseq int, body string) *sip.Message {
server := fmt.Sprintf("%s@%s", sipSerial, sipRealm)
client := fmt.Sprintf("%s@%s", username, sipRealm)
msg := &sip.Message{
Mode: sip.SIP_MESSAGE_REQUEST,
MaxForwards: 70,
UserAgent: "IPC",
Expires: expires,
ContentLength: 0,
}
msg.StartLine = &sip.StartLine{
Method: method,
Uri: sip.NewURI(server),
}
msg.Via = &sip.Via{
Transport: transport,
Host: fmt.Sprintf("%s:%d", srcIP, srcPort),
}
msg.Via.Params = map[string]string{
"branch": randBranch(),
"rport": "-1", //only key,no-value
}
msg.From = &sip.Contact{
Uri: sip.NewURI(client),
Params: nil,
}
msg.From.Params = map[string]string{
"tag": utils.RandNumString(10),
}
msg.To = &sip.Contact{
Uri: sip.NewURI(client),
}
msg.CallID = utils.RandNumString(8)
msg.CSeq = &sip.CSeq{
ID: uint32(cseq),
Method: method,
}
msg.Contact = &sip.Contact{
Uri: sip.NewURI(fmt.Sprintf("%s@%s:%d", username, srcIP, srcPort)),
}
if len(body) > 0 {
msg.ContentLength = len(body)
msg.Body = body
}
msg.Date = time.Now()
return msg
}
//z9hG4bK + 10个随机数字
func randBranch() string {
return fmt.Sprintf("z9hG4bK%s", utils.RandNumString(8))
}
func ParseSDPAttr(data, key string) string {
data = strings.Trim(data, sip.CRLF)
msgArr := strings.Split(data, sip.CRLF)
if len(msgArr) == 0 {
return ""
}
for _, line := range msgArr {
pos := strings.IndexByte(line, '=')
if pos == -1 {
continue
}
k := strings.ToLower(strings.TrimSpace(line[:pos]))
v := strings.TrimSpace(line[pos+1:])
if k == key {
return v
}
}
return ""
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。