public IXmppConnection AddConnection(long rid, IXmppConnection connection) { Args.NotNull(connection, "connection"); lock (connections) { if (hold == connections.Count) { throw new JabberStreamException(StreamErrorCondition.PolicyViolation); } foreach (var pair in connections) { if (window < Math.Abs(rid - pair.Key)) { throw new JabberStreamException(StreamErrorCondition.PolicyViolation); } } // cancel inactivity TaskQueue.RemoveTask(SessionId); connection.SessionId = SessionId; connections.Add(rid, connection); // add wait timeout TaskQueue.AddTask(rid.ToString(), () => SendAndClose(rid, new Body(), null), waitTimeout); } return(this); }
protected void AddNewXmppConnection(IXmppConnection xmppConnection) { if (xmppConnection == null) { throw new ArgumentNullException("xmppConnection"); } try { locker.EnterWriteLock(); connections.Add(xmppConnection.Id, xmppConnection); xmppConnection.Closed += XmppConnectionClosed; } finally { locker.ExitWriteLock(); } var handler = OpenXmppConnection; if (handler != null) { handler(this, new XmppConnectionOpenEventArgs(xmppConnection)); } xmppConnection.BeginReceive(); }
public void ProcessError(IXmppConnection connection, Exception error) { try { Args.NotNull(error, "error"); var session = GetSession(connection); Log.Error("ProcessError session {0}\r\n{1}", session.Id, error); try { foreach (var handler in router.GetErrorHandlers()) { ProcessResult(handler.OnError(error, session, context)); } } finally { ProcessResult(defaultHandler.OnError(error, session, context)); } } catch (Exception innererror) { Log.Error(innererror); } }
public XmppConnectionOpenEventArgs(IXmppConnection xmppConnection) { if (xmppConnection == null) { throw new ArgumentNullException("xmppConnection"); } XmppConnection = xmppConnection; }
private void NewConnection(IXmppConnection connection) { try { connection.BeginReceive(handlerManager); } catch { connection.Close(); throw; } }
protected void AddNewXmppConnection(IXmppConnection xmppConnection) { if (xmppConnection == null) { throw new ArgumentNullException("xmppConnection"); } connections.TryAdd(xmppConnection.Id, xmppConnection); xmppConnection.Closed += XmppConnectionClosed; OpenXmppConnection(this, new XmppConnectionOpenEventArgs(xmppConnection)); xmppConnection.BeginReceive(); }
public void ProcessElement(IXmppConnection connection, Element element) { try { Args.NotNull(element, "element"); var session = GetSession(connection); if (ProcessValidation(defaultInvoker, element, session, context)) { var to = element.GetAttribute("to"); var jid = to != null && !session.Jid.IsServer ? new Jid(to) : session.Jid; var handlers = router.GetElementHandlers(element.GetType(), jid); var processed = false; foreach (var handler in handlers) { processed = true; if (ProcessValidation(handler, element, session, context)) { Log.Information("ProcessElement handler {0} on {1}, session {2}", handler.HandlerId, jid, session.Id); ProcessResult(handler.ProcessElement(element, session, context)); } else { Log.Information("ProcessElement skip, handler {0} on {1}, session {2}", handler.HandlerId, jid, session.Id); } } if (!processed) { ProcessResult(defaultInvoker.ProcessElement(element, session, context)); } } else { Log.Information("ProcessElement skip, session {0}", session.Id); } } catch (Exception error) { ProcessError(connection, error); } }
public void ProcessClose(IXmppConnection connection) { try { var session = GetSession(connection); try { foreach (var handler in router.GetCloseHandlers()) { ProcessResult(handler.OnClose(session, context)); } } finally { ProcessResult(defaultHandler.OnClose(session, context)); } } catch (Exception error) { ProcessError(connection, error); } }
public XmppConnectionOpenEventArgs(IXmppConnection xmppConnection) { if (xmppConnection == null) throw new ArgumentNullException("xmppConnection"); XmppConnection = xmppConnection; }
protected void AddNewXmppConnection(IXmppConnection xmppConnection) { if (xmppConnection == null) throw new ArgumentNullException("xmppConnection"); try { locker.EnterWriteLock(); connections.Add(xmppConnection.Id, xmppConnection); xmppConnection.Closed += XmppConnectionClosed; } finally { locker.ExitWriteLock(); } var handler = OpenXmppConnection; if (handler != null) handler(this, new XmppConnectionOpenEventArgs(xmppConnection)); xmppConnection.BeginReceive(); }
internal StanzaSender(IXmppConnection connection) { _connection = connection; _sendThread = new Thread(SendLoop) { Name = "SendStanzaLoop", IsBackground = true }; _sendThread.Start(); }
public PacketGrabber(IXmppConnection conn) { _connection = conn; _data = new Hashtable(); }
public XmppSession(IXmppConnection connection) : this(connection.SessionId ?? id.CreateId()) { Connection = connection; }
private XmppSession GetSession(IXmppConnection connection) { Args.NotNull(connection, "endpoint"); return(sessionManager.GetSession(connection.SessionId) ?? new XmppSession(connection)); }