|
|
|
@ -41,6 +41,12 @@ var bigSession []*IcsSession
|
|
|
|
|
var onceSession sync.Once
|
|
|
|
|
var channelNum int
|
|
|
|
|
|
|
|
|
|
var m *sync.Mutex
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
m = &sync.Mutex{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getSessionInstance(SIPNeter *icsnet.IcsNeter) []*IcsSession {
|
|
|
|
|
//l := icslog.GetIcsLog()
|
|
|
|
|
|
|
|
|
@ -315,68 +321,117 @@ func (sm *SessionManager) Run() (icserr *icserror.IcsError) {
|
|
|
|
|
sip.Method, sip.ResType, sip.Cseq)
|
|
|
|
|
|
|
|
|
|
s, serr := FindSession(sip)
|
|
|
|
|
if serr != nil { //not found session, create new
|
|
|
|
|
name1 := strings.SplitN(sip.To, "@", 2)
|
|
|
|
|
name2 := strings.SplitN(name1[0], ":", 2)
|
|
|
|
|
agentname := name2[1]
|
|
|
|
|
s, serr = AllocSession(agentname, sip.GetCallID())
|
|
|
|
|
if serr != nil {
|
|
|
|
|
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())
|
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
|
if serr != nil { //not found session
|
|
|
|
|
// name1 := strings.SplitN(sip.To, "@", 2)
|
|
|
|
|
// name2 := strings.SplitN(name1[0], ":", 2)
|
|
|
|
|
// agentname := name2[1]
|
|
|
|
|
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:%s@%s;transport=%s", "192.168.0.222:5090", "AISB",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)
|
|
|
|
|
}
|
|
|
|
|
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())
|
|
|
|
|
s.SetSessionMethod(sip)
|
|
|
|
|
//session start
|
|
|
|
|
s.Start()
|
|
|
|
|
continue
|
|
|
|
|
// s, serr = AllocSession(agentname, sip.GetCallID())
|
|
|
|
|
// if serr != nil {
|
|
|
|
|
// 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
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Session found [%s][%s]", sip.GetCallID(), s.callID)
|
|
|
|
|
if sip.Method == icspacketparser.ICS_SIP_METHOD_INVITE {
|
|
|
|
|