public void ProcessBody(Body body, HttpListenerContext ctx)
        {
            log.DebugFormat("Start process body connection {0}", Id);
            lock (locker)
            {
                CloseRequest(false);

                lastRequestTime = DateTime.Now;
                currentRequest  = new BoshXmppRequest(Id, body, ctx);
            }
            if (body.HasChildElements)
            {
                if (body.FirstChild.GetAttribute("type") == "notification")
                {
                    //сonfiguring store and write to data base
                    DbPushStore dbPushStore = new DbPushStore();
                    var         properties  = new Dictionary <string, string>(1);
                    properties.Add("connectionStringName", "default");
                    dbPushStore.Configure(properties);
                    dbPushStore.SaveUserEndpoint(
                        body.FirstChild.GetAttribute("username"),
                        body.FirstChild.GetAttribute("endpoint"),
                        body.FirstChild.GetAttribute("browser"));
                }
            }

            if (body.Type == BoshType.terminate)
            {
                Close();
                return;
            }

            if (Volatile.Read(ref closed) == 1)
            {
                CloseRequest(true);
                return;
            }

            IdleWatcher.UpdateTimeout(Id, waitTimeout);

            if (string.IsNullOrEmpty(body.Sid) || body.XmppRestart)
            {
                var stream = new Stream
                {
                    Prefix    = Uri.PREFIX,
                    Namespace = Uri.STREAM,
                    Version   = body.Version,
                    Language  = body.GetAttribute("lang"),
                    To        = body.To,
                };
                XmppStreamStart(this, new XmppStreamStartEventArgs(Id, stream, Uri.CLIENT));
            }
            foreach (var element in body.ChildNodes.OfType <Element>())
            {
                XmppStreamElement(this, new XmppStreamEventArgs(Id, element));
            }

            Send((Node)null, null); // try to send a non-empty buffer
        }
Example #2
0
        public void ProcessBody(Body body, HttpListenerContext ctx)
        {
            log.DebugFormat("Start process body connection {0}", Id);

            lock (locker)
            {
                CloseRequest(false);

                lastRequestTime = DateTime.Now;
                currentRequest  = new BoshXmppRequest(Id, body, ctx);
            }

            if (body.Type == BoshType.terminate)
            {
                Close();
                return;
            }

            if (Volatile.Read(ref closed) == 1)
            {
                CloseRequest(true);
                return;
            }

            IdleWatcher.UpdateTimeout(Id, waitTimeout);

            if (string.IsNullOrEmpty(body.Sid) || body.XmppRestart)
            {
                var stream = new Stream
                {
                    Prefix    = Uri.PREFIX,
                    Namespace = Uri.STREAM,
                    Version   = body.Version,
                    Language  = body.GetAttribute("lang"),
                    To        = body.To,
                };
                XmppStreamStart(this, new XmppStreamStartEventArgs(Id, stream, Uri.CLIENT));
            }
            foreach (var element in body.ChildNodes.OfType <Element>())
            {
                XmppStreamElement(this, new XmppStreamEventArgs(Id, element));
            }

            Send((Node)null, null); // try to send a non-empty buffer
        }
        public void ProcessBody(Body body, HttpListenerContext ctx)
        {
            try
            {
                IdleWatcher.UpdateTimeout(Id, TimeSpan.MaxValue);

                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (ctx == null)
                {
                    throw new ArgumentNullException("httpContext");
                }

                log.DebugFormat("Start process body connection {0}\r\n{1}\r\n", Id, body);

                if (!ValidateBody(body))
                {
                    BoshXmppHelper.TerminateBoshSession(ctx, "bad-request");
                    return;
                }
                if (body.Type == BoshType.terminate)
                {
                    Close();
                    ctx.Response.Close();
                    return;
                }

                waitDrop.Set();
                waitDrop.Reset();

                ReadBodyHeaders(body);

                if (string.IsNullOrEmpty(body.Sid) || body.XmppRestart)
                {
                    InvokeStreamStart(body);
                }
                foreach (var node in body.ChildNodes)
                {
                    if (node is Element)
                    {
                        InvokeStreamElement((Element)node);
                    }
                }

                WriteBodyHeaders(body);

                log.DebugFormat("Connection {0} WAIT ...", Id);
                var waitResult = WaitAnswerOrDrop();

                if (waitResult == WaitResult.Success)
                {
                    log.DebugFormat("Connection {0} send answer", Id);
                    SendAnswer(body, ctx);
                }
                else if (waitResult == WaitResult.Timeout)
                {
                    log.DebugFormat("Connection {0} drop by timeout", Id);
                    BoshXmppHelper.SendAndCloseResponse(ctx, new Body().ToString());
                }
                else
                {
                    log.DebugFormat("Connection {0} terminate", Id);
                    BoshXmppHelper.TerminateBoshSession(ctx, body);
                }
            }
            finally
            {
                IdleWatcher.UpdateTimeout(Id, inactivityPeriod);
            }
        }
Example #4
0
 public void UpdateTimeout()
 {
     _log.DebugFormat("Update timeout of connection {0}.", Id);
     IdleWatcher.UpdateTimeout(Id, _inactivityPeriod);
 }