private void OnWait(object _, TimeoutEventArgs a)
 {
     try
     {
         lock (locker)
         {
             if (currentRequest != null)
             {
                 log.DebugFormat("Close request {0}", Id);
                 currentRequest.Close(false);
                 currentRequest = null;
             }
         }
     }
     finally
     {
         if (lastRequestTime + waitTimeout + inactivityTimeout < DateTime.Now)
         {
             Close();
         }
         else
         {
             IdleWatcher.StartWatch(Id, waitTimeout, OnWait);
         }
     }
 }
Exemplo n.º 2
0
 public SignalRXmppConnection(string connectionId, XmppServer xmppServer)
 {
     Id          = connectionId;
     _xmppServer = xmppServer;
     IdleWatcher.StopWatch(Id);
     IdleWatcher.StartWatch(Id, _inactivityPeriod, IdleTimeout);
     _log.DebugFormat("Create new SignalR connection Id = {0}.", Id);
 }
Exemplo n.º 3
0
        private IQ GetUserDisco(XmppStream stream, IQ iq, XmppHandlerContext context)
        {
            if (iq.To.HasResource)
            {
                var session = context.SessionManager.GetSession(iq.To);

                if (session != null && iq.Query is DiscoInfo)
                {
                    var discoInfo = session.ClientInfo.GetDiscoInfo(((DiscoInfo)iq.Query).Node);
                    if (discoInfo != null)
                    {
                        iq.Query = discoInfo;
                        return(ToResult(iq));
                    }
                }

                if (session == null)
                {
                    return(XmppStanzaError.ToRecipientUnavailable(iq));
                }
                context.Sender.SendTo(session, iq);
                IdleWatcher.StartWatch(iq.Id, TimeSpan.FromSeconds(4.5f), IQLost, iq);
            }
            else
            {
                if (iq.Query is DiscoInfo && context.UserManager.IsUserExists(iq.To))
                {
                    ((DiscoInfo)iq.Query).AddIdentity(new DiscoIdentity("registered", "account"));
                    return(ToResult(iq));
                }
                else if (iq.Query is DiscoItems)
                {
                    foreach (var s in context.SessionManager.GetBareJidSessions(iq.To))
                    {
                        ((DiscoItems)iq.Query).AddDiscoItem(new DiscoItem()
                        {
                            Jid = s.Jid
                        });
                    }
                    return(ToResult(iq));
                }
                return(XmppStanzaError.ToServiceUnavailable(iq));
            }
            return(null);
        }
Exemplo n.º 4
0
        public override IQ HandleIQ(XmppStream stream, IQ iq, XmppHandlerContext context)
        {
            var answer = new IQ(IqType.result)
            {
                Id   = iq.Id,
                To   = iq.From,
                From = iq.To,
            };

            //iq sended to server
            if (iq.Type == IqType.get && (!iq.HasTo || iq.To.IsServer || iq.To == iq.From))
            {
                if (iq.Query is Version)
                {
                    answer.Query = new Version()
                    {
                        Name = "TeamLab Jabber Server",
                        Os   = System.Environment.OSVersion.ToString(),
                        Ver  = "1.0",
                    };
                    return(answer);
                }
                else if (iq.Query is Ping)
                {
                    return(answer);
                }
                return(XmppStanzaError.ToServiceUnavailable(iq));
            }

            if (iq.Type == IqType.get && iq.HasTo)
            {
                //resend iq
                var sessionTo   = context.SessionManager.GetSession(iq.To);
                var sessionFrom = context.SessionManager.GetSession(iq.From);
                if (sessionTo != null && sessionFrom != null)
                {
                    if (string.IsNullOrEmpty(iq.Id))
                    {
                        iq.Id = System.Guid.NewGuid().ToString("N");
                    }

                    IdleWatcher.StartWatch(
                        iq.Id + iq.From,
                        System.TimeSpan.FromSeconds(3),
                        (s, e) => { context.Sender.SendTo(sessionFrom, XmppStanzaError.ToServiceUnavailable(iq)); });
                    context.Sender.SendTo(sessionTo, iq);
                }
                else
                {
                    return(XmppStanzaError.ToRecipientUnavailable(iq));
                }
            }
            if (iq.Type == IqType.error || iq.Type == IqType.result)
            {
                if (!iq.HasTo)
                {
                    return(XmppStanzaError.ToBadRequest(iq));
                }

                IdleWatcher.StopWatch(iq.Id + iq.To);
                var session = context.SessionManager.GetSession(iq.To);
                if (session != null)
                {
                    context.Sender.SendTo(session, iq);
                }
            }
            return(null);
        }
Exemplo n.º 5
0
 public BoshXmppConnection()
 {
     Id = UniqueId.CreateNewId();
     IdleWatcher.StartWatch(Id, inactivityPeriod, IdleTimeout);
     log.DebugFormat("Create new Bosh connection Id = {0}", Id);
 }
 public void BeginReceive()
 {
     IdleWatcher.StartWatch(Id, waitTimeout, OnWait);
 }