public async Task <IHttpActionResult> Post(KamailioSipEvent sipEvent)
        {
            if (!_settingsManager.UseSipEvent)
            {
                if (log.IsTraceEnabled)
                {
                    log.Warn("Receiving event but receiver is not ON for 'UseSipEvent'");
                }
                return(Ok());
            }

            if (log.IsTraceEnabled)
            {
                Stream stream = await Request.Content.ReadAsStreamAsync();

                stream.Seek(0, SeekOrigin.Begin);
                var body = await Request.Content.ReadAsStringAsync();

                log.Trace($"Request {Request} Body {body}");
            }

            using (new TimeMeasurer("Incoming SIP event"))
            {
                if (sipEvent == null)
                {
                    log.Warn("SIP event controller received empty data");
                    return(BadRequest());
                }

                var sipMessage = _sipEventParser.Parse(sipEvent);

                if (sipMessage == null)
                {
                    log.Warn("Incorrect SIP message format: ", sipEvent);
                    return(BadRequest());
                }

                SipEventHandlerResult result = _sipMessageManager.HandleSipMessage(sipMessage);

                if (log.IsDebugEnabled)
                {
                    log.Debug("SIP message, Handled: {0}, Parsed: {1}, Result: {2}", sipEvent.ToLogString(), sipMessage.ToDebugString(), result?.ChangeStatus);
                }

                if (result == null)
                {
                    log.Warn("Kamailio message was handled but result was null");
                }
                else if (result.ChangeStatus != SipEventChangeStatus.NothingChanged)
                {
                    _guiHubUpdater.Update(result);    // First web gui
                    _statusHubUpdater.Update(result); // Then codec status to external clients
                }

                return(Ok());
            }
        }
Beispiel #2
0
        public IHttpActionResult Post([FromBody] string message)
        {
            if (!_settingsManager.UseOldKamailioEvent)
            {
                if (log.IsTraceEnabled)
                {
                    log.Warn("Receiving event but receiver is not ON for 'UseOldKamailioEvent'");
                }
                return(Ok());
            }

            using (new TimeMeasurer("Incoming Kamailio event"))
            {
                if (string.IsNullOrWhiteSpace(message))
                {
                    log.Warn("Kamailio event controller received empty data");
                    return(BadRequest());
                }

                SipMessageBase sipMessage = _kamailioMessageParser.Parse(message);

                if (sipMessage == null)
                {
                    log.Warn("Incorrect Kamailio message format: {0}", message);
                    return(BadRequest());
                }

                SipEventHandlerResult result = _sipMessageManager.HandleSipMessage(sipMessage);

                if (log.IsDebugEnabled)
                {
                    log.Debug("SIP message, Handled: {0}, Parsed: {1}, Result: {2}", message, sipMessage.ToDebugString(), result?.ChangeStatus);
                }

                if (result == null)
                {
                    log.Warn("Kamailio message was handled but result was null");
                }
                else if (result.ChangeStatus != SipEventChangeStatus.NothingChanged)
                {
                    _guiHubUpdater.Update(result);    // First web gui
                    _statusHubUpdater.Update(result); // Then codec status to external clients
                }

                return(Ok());
            }
        }