public override IQ HandleIQ(XmppStream stream, IQ iq, XmppHandlerContext context) { if (iq.Type == IqType.result || iq.Type == IqType.error) { IdleWatcher.StopWatch(iq.Id); var session = context.SessionManager.GetSession(iq.From); if (session != null && iq.Query is DiscoInfo) { session.ClientInfo.SetDiscoInfo((DiscoInfo)iq.Query); } if (iq.HasTo) { session = context.SessionManager.GetSession(iq.To); if (session != null) { context.Sender.SendTo(session, iq); } return(null); } } else if (iq.HasTo && iq.To.HasUser) { return(GetUserDisco(stream, iq, context)); } return(base.HandleIQ(stream, iq, context)); }
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); }
public void Close() { lock (this) { if (closed) { return; } closed = true; waitDrop.Set(); waitDrop.Close(); waitAnswer.Close(); IdleWatcher.StopWatch(Id); try { var handler = XmppStreamEnd; if (handler != null) { XmppStreamEnd(this, new XmppStreamEndEventArgs(Id, sendBuffer)); } } catch { } finally { sendBuffer.Clear(); } try { var handler = Closed; if (handler != null) { handler(this, new XmppConnectionCloseEventArgs()); } } catch { } log.DebugFormat("Close connection {0}", Id); } }
public void Close() { if (Interlocked.CompareExchange(ref closed, 1, 0) == 0) { lock (wait) { Monitor.PulseAll(wait); } IdleWatcher.StopWatch(Id); try { var handler = XmppStreamEnd; if (handler != null) { XmppStreamEnd(this, new XmppStreamEndEventArgs(Id, sendBuffer)); } } catch { } finally { sendBuffer = new ConcurrentQueue <Node>(); } try { var handler = Closed; if (handler != null) { handler(this, new XmppConnectionCloseEventArgs()); } } catch { } log.DebugFormat("Close connection {0}", Id); } }
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); }
public new void CloseXmppConnection(string connectionId) { IdleWatcher.StopWatch(connectionId); base.CloseXmppConnection(connectionId); }