public void SendAsyncSip(ServerAsyncEventArgs e) { if (AjaxWebsocket.IsAjax(e)) { ajax.ProcessOutgoing(e); } else { e.UserTokenForSending2 = SipModule; serversManager.SendAsync(e); } }
public TransportLayer(ServersManager <Connection> serversManager1, Opcodes?websocketResponseFrame) { ChangeSettings(websocketResponseFrame); serversManager = serversManager1; serversManager.ServerAdded += ServersManager_ServerAdded; serversManager.ServerRemoved += ServersManager_ServerRemoved; serversManager.ServerInfo += ServersManager_ServerInfo; serversManager.NewConnection += ServersManager_NewConnection; serversManager.EndConnection += ServersManager_EndConnection; serversManager.Received += ServersManager_Received; serversManager.Sent += ServersManager_Sent; serversManager.BeforeSend += ServersManager_BeforeSend; ajax = new AjaxWebsocket(); ajax.SendAsync = SendAsyncAjax; }
public TransportLayer(ServersManager<Connection> serversManager1, Opcodes? websocketResponseFrame) { ChangeSettings(websocketResponseFrame); serversManager = serversManager1; serversManager.ServerAdded += ServersManager_ServerAdded; serversManager.ServerRemoved += ServersManager_ServerRemoved; serversManager.ServerInfo += ServersManager_ServerInfo; serversManager.NewConnection += ServersManager_NewConnection; serversManager.EndConnection += ServersManager_EndConnection; serversManager.Received += ServersManager_Received; serversManager.Sent += ServersManager_Sent; serversManager.BeforeSend += ServersManager_BeforeSend; ajax = new AjaxWebsocket(); ajax.SendAsync = SendAsyncAjax; }
protected override ParseResult Parse(ArraySegment <byte> data) { switch (mode) { case Modes.Sip: { if (keepAliveCount != 0) { return(SkipKeepAlive(data)); } else { var sipReader = SipReader.GetEmpty(); int headerLength = sipReader.Parse(data.Array, data.Offset, data.Count); if (sipReader.IsFinal) { return(ParseResult.HeaderDone(headerLength, sipReader.HasContentLength ? sipReader.ContentLength : 0)); } if (sipReader.IsError) { if (IsKeepAliveByte(data.Array[data.Offset], 0)) { return(SkipKeepAlive(data)); } else { mode = Modes.Http; goto case Modes.Http; } } return(ParseResult.NotEnoughData()); } } case Modes.Http: { var httpReader = HttpReaderx.GetEmpty(); httpHeaderLength = httpReader.Parse(data.Array, data.Offset, data.Count); if (httpReader.IsFinal) { httpContentLength = httpReader.HasContentLength ? httpReader.ContentLength : 0; if (AjaxWebsocket.IsAjax(httpReader, data.Array)) { mode = Modes.Ajax; goto case Modes.Ajax; } return(ParseResult.HeaderDone(httpHeaderLength, httpContentLength)); } if (httpReader.IsError) { return(ParseResult.Error()); } return(ParseResult.NotEnoughData()); } case Modes.WebSocket: { if (wsWaitHeader) { int used = wsHeader.Parse(data); if (wsHeader.IsDone) { wsWaitHeader = false; } return(ParseResult.Skip(used)); } else { if (IsSipWebSocket == false) { return(ParseResult.HeaderDone(0, wsHeader.PayloadLength)); } else { var sipReader = SipReader.GetEmpty(); int headerLength = sipReader.Parse(data.Array, data.Offset, data.Count); if (sipReader.IsFinal) { return(ParseResult.HeaderDone(headerLength, sipReader.HasContentLength ? sipReader.ContentLength : 0)); } if (sipReader.IsError) { return(ParseResult.Error()); } return(ParseResult.NotEnoughData()); } } } case Modes.Ajax: { if (httpContentLength > 0) { if (httpHeaderLength < data.Count) { var sipReader = SipReader.GetEmpty(); int sipHeaderLength = sipReader.Parse(data.Array, data.Offset + httpHeaderLength, data.Count - httpHeaderLength); if (sipReader.IsFinal) { return(ParseResult.HeaderDone(httpHeaderLength + sipHeaderLength, sipReader.HasContentLength ? sipReader.ContentLength : 0)); } if (sipReader.IsError || httpContentLength <= data.Count - httpHeaderLength) { return(ParseResult.Error()); } } HttpReaderx.Invalidate(); return(ParseResult.NotEnoughData()); } else { return(ParseResult.HeaderDone(httpHeaderLength, 0)); } } default: throw new NotImplementedException(); } }