Ejemplo n.º 1
0
func (self *KamailioSessionManager) DisconnectSession(ev engine.Event, connId, notify string) error {
	sessionIds := ev.GetSessionIds()
	disconnectEv := &KamSessionDisconnect{Event: CGR_SESSION_DISCONNECT, HashEntry: sessionIds[0], HashId: sessionIds[1], Reason: notify}
	if err := self.conns[connId].Send(disconnectEv.String()); err != nil {
		utils.Logger.Err(fmt.Sprintf("<SM-Kamailio> Failed sending disconnect request, error %s, connection id: %s", err.Error(), connId))
		return err
	}
	return nil
}
Ejemplo n.º 2
0
// Disconnects the session
func (osm *OsipsSessionManager) DisconnectSession(ev engine.Event, connId, notify string) error {
	sessionIds := ev.GetSessionIds()
	if len(sessionIds) != 2 {
		errMsg := fmt.Sprintf("Failed disconnecting session for event: %+v, notify: %s, dialogId: %v", ev, notify, sessionIds)
		utils.Logger.Err(fmt.Sprintf("<SM-OpenSIPS> " + errMsg))
		return errors.New(errMsg)
	}
	cmd := fmt.Sprintf(":dlg_end_dlg:\n%s\n%s\n\n", sessionIds[0], sessionIds[1])
	if reply, err := osm.miConn.SendCommand([]byte(cmd)); err != nil {
		utils.Logger.Err(fmt.Sprintf("<SM-OpenSIPS> Failed disconnecting session for event: %+v, notify: %s, dialogId: %v, error: <%s>", ev, notify, sessionIds, err))
		return err
	} else if !bytes.HasPrefix(reply, []byte("200 OK")) {
		errStr := fmt.Sprintf("Failed disconnecting session for event: %+v, notify: %s, dialogId: %v", ev, notify, sessionIds)
		utils.Logger.Err("<SM-OpenSIPS> " + errStr)
		return errors.New(errStr)
	}
	return nil
}