|
|
@ -41,6 +41,12 @@ var bigSession []*IcsSession
|
|
|
|
var onceSession sync.Once
|
|
|
|
var onceSession sync.Once
|
|
|
|
var channelNum int
|
|
|
|
var channelNum int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var m *sync.Mutex
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
|
|
|
m = &sync.Mutex{}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func getSessionInstance(SIPNeter *icsnet.IcsNeter) []*IcsSession {
|
|
|
|
func getSessionInstance(SIPNeter *icsnet.IcsNeter) []*IcsSession {
|
|
|
|
//l := icslog.GetIcsLog()
|
|
|
|
//l := icslog.GetIcsLog()
|
|
|
|
|
|
|
|
|
|
|
@ -315,68 +321,117 @@ func (sm *SessionManager) Run() (icserr *icserror.IcsError) {
|
|
|
|
sip.Method, sip.ResType, sip.Cseq)
|
|
|
|
sip.Method, sip.ResType, sip.Cseq)
|
|
|
|
|
|
|
|
|
|
|
|
s, serr := FindSession(sip)
|
|
|
|
s, serr := FindSession(sip)
|
|
|
|
if serr != nil { //not found session, create new
|
|
|
|
if serr != nil { //not found session
|
|
|
|
name1 := strings.SplitN(sip.To, "@", 2)
|
|
|
|
// name1 := strings.SplitN(sip.To, "@", 2)
|
|
|
|
name2 := strings.SplitN(name1[0], ":", 2)
|
|
|
|
// name2 := strings.SplitN(name1[0], ":", 2)
|
|
|
|
agentname := name2[1]
|
|
|
|
// agentname := name2[1]
|
|
|
|
s, serr = AllocSession(agentname, sip.GetCallID())
|
|
|
|
if conf.Representative.Value && sip.Source == "486" {
|
|
|
|
if serr != nil {
|
|
|
|
l.Printf(icslog.LOG_LEVEL_ERROR, -1, "All Agent Calling!!!!!")
|
|
|
|
l.Printf(icslog.LOG_LEVEL_ERROR, -1, "Licensed Session number[%d:%s] is EXCEEDED-%s",
|
|
|
|
sipPort := conf.SIPConfig.Port
|
|
|
|
conf.GetChannelNum(), agentname, serr.GetMessage())
|
|
|
|
// sipProxy := conf.SIPConfig.SIPProxy
|
|
|
|
if conf.Representative.Value && sip.Source == "486" {
|
|
|
|
transport := conf.SIPConfig.Transport
|
|
|
|
l.Printf(icslog.LOG_LEVEL_ERROR, -1, "All Agent Calling!!!!!")
|
|
|
|
// remoteaddr := icsnet.NewNetAddrWithIPAddr(sipProxy)
|
|
|
|
sipPort := conf.SIPConfig.Port
|
|
|
|
// localAddrStr := fmt.Sprintf("0.0.0.0:%d", sipPort)
|
|
|
|
// sipProxy := conf.SIPConfig.SIPProxy
|
|
|
|
// localAddr := icsnet.NewNetAddrWithIPAddr(localAddrStr)
|
|
|
|
transport := conf.SIPConfig.Transport
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
// remoteaddr := icsnet.NewNetAddrWithIPAddr(sipProxy)
|
|
|
|
ip := conf.InfoConfig.ServerIP
|
|
|
|
// localAddrStr := fmt.Sprintf("0.0.0.0:%d", sipPort)
|
|
|
|
ackMethod := fmt.Sprintf("sip:%s@%s;transport=%s", "192.168.0.222:5090", "AISB",transport)
|
|
|
|
// localAddr := icsnet.NewNetAddrWithIPAddr(localAddrStr)
|
|
|
|
reqAck := sipasm.NewSIPMessage(sipasm.ICSSIP_METHOD_ACK, ackMethod)
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
maxforwards := "70"
|
|
|
|
ip := conf.InfoConfig.ServerIP
|
|
|
|
// s.uri = fmt.Sprintf("sip:%s@%s", conf.Representative.Name, ip)
|
|
|
|
ackMethod := fmt.Sprintf("sip:01025670081@%s;transport=%s", "192.168.0.222:5090", transport)
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_INFO, -1, "Set URI [%s]", s.uri)
|
|
|
|
reqAck := sipasm.NewSIPMessage(sipasm.ICSSIP_METHOD_ACK, ackMethod)
|
|
|
|
contact := fmt.Sprintf("<sip:%s@%s:%d;transport=%s>", conf.Representative.Name, ip, sipPort, transport)
|
|
|
|
maxforwards := "70"
|
|
|
|
userAgent := conf.InfoConfig.Product
|
|
|
|
// s.uri = fmt.Sprintf("sip:%s@%s", conf.Representative.Name, ip)
|
|
|
|
allow := "REGISTER,OPTIONS,INVITE,ACK,CANCEL,BYE,NOTIFY,PRACK,REFER,INFO,SUBSCRIBE,UPDATE"
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_INFO, -1, "Set URI [%s]", s.uri)
|
|
|
|
supported := "timer,path,replaces"
|
|
|
|
contact := fmt.Sprintf("<sip:%s@%s:%d;transport=%s>", conf.Representative.Name, ip, sipPort, transport)
|
|
|
|
|
|
|
|
userAgent := conf.InfoConfig.Product
|
|
|
|
for _, viav := range sip.Via {
|
|
|
|
allow := "REGISTER,OPTIONS,INVITE,ACK,CANCEL,BYE,NOTIFY,PRACK,REFER,INFO,SUBSCRIBE,UPDATE"
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_VIA, viav)
|
|
|
|
supported := "timer,path,replaces"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, viav := range sip.Via {
|
|
|
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_VIA, viav)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_MAX_FORWARDS, maxforwards)
|
|
|
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_FROM, sip.From)
|
|
|
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_TO, sip.To)
|
|
|
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_CALL_ID, sip.CallID)
|
|
|
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_CSEQ, sip.Cseq)
|
|
|
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTACT, contact)
|
|
|
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_USER_AGENT, userAgent)
|
|
|
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_ALLOW, allow)
|
|
|
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_SUPPORTED, supported)
|
|
|
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTENT_LENGTH, "0")
|
|
|
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_TERMINATOR)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// wlen, werr := (*s.sipNeter).WriteSIPTo([]byte(reqAck.String()), s.remoteSIPAddr)
|
|
|
|
|
|
|
|
wlen, werr := (sm.SIPNeter).WriteSIP([]byte(reqAck.String()))
|
|
|
|
|
|
|
|
if werr != nil {
|
|
|
|
|
|
|
|
l.Print(icslog.LOG_LEVEL_FATAL, s.ID, werr.GetMessage())
|
|
|
|
|
|
|
|
return werr
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, -1, "Sent Data(%d) [%s]->[%s]>\n%s",
|
|
|
|
|
|
|
|
wlen,
|
|
|
|
|
|
|
|
(sm.SIPNeter).LocalAddr().String(),
|
|
|
|
|
|
|
|
(sm.SIPNeter).RemoteAddr().String(),
|
|
|
|
|
|
|
|
reqAck.String())
|
|
|
|
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_MAX_FORWARDS, maxforwards)
|
|
|
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_FROM, sip.From)
|
|
|
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_TO, sip.To)
|
|
|
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_CALL_ID, sip.CallID)
|
|
|
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_CSEQ, sip.Cseq)
|
|
|
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTACT, contact)
|
|
|
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_USER_AGENT, userAgent)
|
|
|
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_ALLOW, allow)
|
|
|
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_SUPPORTED, supported)
|
|
|
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTENT_LENGTH, "0")
|
|
|
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_TERMINATOR)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// wlen, werr := (*s.sipNeter).WriteSIPTo([]byte(reqAck.String()), s.remoteSIPAddr)
|
|
|
|
|
|
|
|
wlen, werr := (sm.SIPNeter).WriteSIP([]byte(reqAck.String()))
|
|
|
|
|
|
|
|
if werr != nil {
|
|
|
|
|
|
|
|
l.Print(icslog.LOG_LEVEL_FATAL, -1, werr.GetMessage())
|
|
|
|
|
|
|
|
return werr
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, -1, "Sent Data(%d) [%s]->[%s]>\n%s",
|
|
|
|
|
|
|
|
wlen,
|
|
|
|
|
|
|
|
(sm.SIPNeter).LocalAddr().String(),
|
|
|
|
|
|
|
|
(sm.SIPNeter).RemoteAddr().String(),
|
|
|
|
|
|
|
|
reqAck.String())
|
|
|
|
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
}
|
|
|
|
}
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, -1, "Session Allocated. Session ID[%d] Call ID[%s]", s.ID, sip.GetCallID())
|
|
|
|
continue
|
|
|
|
s.SetSessionMethod(sip)
|
|
|
|
// s, serr = AllocSession(agentname, sip.GetCallID())
|
|
|
|
//session start
|
|
|
|
// if serr != nil {
|
|
|
|
s.Start()
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_ERROR, -1, "Licensed Session number[%d:%s] is EXCEEDED-%s",
|
|
|
|
|
|
|
|
// conf.GetChannelNum(), agentname, serr.GetMessage())
|
|
|
|
|
|
|
|
// if conf.Representative.Value && sip.Source == "486" {
|
|
|
|
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_ERROR, -1, "All Agent Calling!!!!!")
|
|
|
|
|
|
|
|
// sipPort := conf.SIPConfig.Port
|
|
|
|
|
|
|
|
// // sipProxy := conf.SIPConfig.SIPProxy
|
|
|
|
|
|
|
|
// transport := conf.SIPConfig.Transport
|
|
|
|
|
|
|
|
// // remoteaddr := icsnet.NewNetAddrWithIPAddr(sipProxy)
|
|
|
|
|
|
|
|
// // localAddrStr := fmt.Sprintf("0.0.0.0:%d", sipPort)
|
|
|
|
|
|
|
|
// // localAddr := icsnet.NewNetAddrWithIPAddr(localAddrStr)
|
|
|
|
|
|
|
|
// //////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ip := conf.InfoConfig.ServerIP
|
|
|
|
|
|
|
|
// ackMethod := fmt.Sprintf("sip:01025670081@%s;transport=%s", "192.168.0.222:5090", transport)
|
|
|
|
|
|
|
|
// reqAck := sipasm.NewSIPMessage(sipasm.ICSSIP_METHOD_ACK, ackMethod)
|
|
|
|
|
|
|
|
// maxforwards := "70"
|
|
|
|
|
|
|
|
// // s.uri = fmt.Sprintf("sip:%s@%s", conf.Representative.Name, ip)
|
|
|
|
|
|
|
|
// // l.Printf(icslog.LOG_LEVEL_INFO, -1, "Set URI [%s]", s.uri)
|
|
|
|
|
|
|
|
// contact := fmt.Sprintf("<sip:%s@%s:%d;transport=%s>", conf.Representative.Name, ip, sipPort, transport)
|
|
|
|
|
|
|
|
// userAgent := conf.InfoConfig.Product
|
|
|
|
|
|
|
|
// allow := "REGISTER,OPTIONS,INVITE,ACK,CANCEL,BYE,NOTIFY,PRACK,REFER,INFO,SUBSCRIBE,UPDATE"
|
|
|
|
|
|
|
|
// supported := "timer,path,replaces"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// for _, viav := range sip.Via {
|
|
|
|
|
|
|
|
// reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_VIA, viav)
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_MAX_FORWARDS, maxforwards)
|
|
|
|
|
|
|
|
// reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_FROM, sip.From)
|
|
|
|
|
|
|
|
// reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_TO, sip.To)
|
|
|
|
|
|
|
|
// reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_CALL_ID, sip.CallID)
|
|
|
|
|
|
|
|
// reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_CSEQ, sip.Cseq)
|
|
|
|
|
|
|
|
// reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTACT, contact)
|
|
|
|
|
|
|
|
// reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_USER_AGENT, userAgent)
|
|
|
|
|
|
|
|
// reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_ALLOW, allow)
|
|
|
|
|
|
|
|
// reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_SUPPORTED, supported)
|
|
|
|
|
|
|
|
// reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTENT_LENGTH, "0")
|
|
|
|
|
|
|
|
// reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_TERMINATOR)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // wlen, werr := (*s.sipNeter).WriteSIPTo([]byte(reqAck.String()), s.remoteSIPAddr)
|
|
|
|
|
|
|
|
// wlen, werr := (sm.SIPNeter).WriteSIP([]byte(reqAck.String()))
|
|
|
|
|
|
|
|
// if werr != nil {
|
|
|
|
|
|
|
|
// l.Print(icslog.LOG_LEVEL_FATAL, s.ID, werr.GetMessage())
|
|
|
|
|
|
|
|
// return werr
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_INFO, -1, "Sent Data(%d) [%s]->[%s]>\n%s",
|
|
|
|
|
|
|
|
// wlen,
|
|
|
|
|
|
|
|
// (sm.SIPNeter).LocalAddr().String(),
|
|
|
|
|
|
|
|
// (sm.SIPNeter).RemoteAddr().String(),
|
|
|
|
|
|
|
|
// reqAck.String())
|
|
|
|
|
|
|
|
// //////////////////////////////////////////////
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// continue
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_INFO, -1, "Session Allocated. Session ID[%d] Call ID[%s]", s.ID, sip.GetCallID())
|
|
|
|
|
|
|
|
// s.SetSessionMethod(sip)
|
|
|
|
|
|
|
|
// //session start
|
|
|
|
|
|
|
|
// s.Start()
|
|
|
|
} else { //found session
|
|
|
|
} else { //found session
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Session found [%s][%s]", sip.GetCallID(), s.callID)
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Session found [%s][%s]", sip.GetCallID(), s.callID)
|
|
|
|
if sip.Method == icspacketparser.ICS_SIP_METHOD_INVITE {
|
|
|
|
if sip.Method == icspacketparser.ICS_SIP_METHOD_INVITE {
|
|
|
|