public void Get_Raw_Sip_Message_Type_Success(string sipMessage, SipMessageType messageTypeExpected) { // *** ARRANGE *** SipMessage rawMessage = new SipMessage(sipMessage); // *** ACT *** SipMessageType messageTypeResult = rawMessage.GetMessageType(); // *** ASSERT *** Assert.Equal(messageTypeExpected, messageTypeResult); }
private void Receive(IAsyncResult result) { Tuple <Socket, BufferSegment> container = (Tuple <Socket, BufferSegment>)result.AsyncState; Socket listenSocket = container.Item1; BufferSegment bs = container.Item2; EndPoint clientEp = new IPEndPoint(IPAddress.Any, 0); int recvBytes = listenSocket.EndReceiveFrom(result, ref clientEp); string recvMsg; while (true) { _logger.Debug("Recieving new bunch of data from socket."); recvMsg = Encoding.ASCII.GetString(bs.Buffer, 0, recvBytes); if (ParsingHelpers.IsSipMessageComplete(recvMsg)) { break; } throw new NotImplementedException("Message wasn't full recieved at one method calling."); } // process sip message SipMessageType messageType = ParsingHelpers.GetSipMessageType(recvMsg); SipMessage sipMessage; if (messageType == SipMessageType.Request) { throw new NotImplementedException("SIP REQUEST decoder not yet implemented."); } else if (messageType == SipMessageType.Response) { sipMessage = SipResponse.CreateSipResponse(recvMsg); } else { _logger.Warn($"Cann't recognize if incomming SIP message is type of REQUEST or RESPONSE:\n {recvMsg}"); throw new ArgumentException("Incomming sip message is invalid... unknown message type."); } _logger.Debug($"New sip message received:\n{sipMessage}"); Via transactionInfo = sipMessage.Headers.Via.First(); if (transactionInfo.IpAddress == ListeningOnIp) { // handle local transaction bool transactionResult = Transactions.TryGetValue(transactionInfo.Branch, out Transaction transaction); if (!transactionResult) { throw new NotImplementedException($"Cann't find transaction with transaction id {transactionInfo.Branch}."); } if (transaction.SetResponse((SipResponse)sipMessage)) { _logger.Info($"Transacion {transactionInfo.Branch} complete."); OnTransactionComplete(transaction); } else { throw new NotImplementedException("Provisional response handling not yet implemented."); } } else { throw new NotImplementedException("Transaction is determined for different endpoint."); } }
/// <summary> /// Constructs a SipMessage /// </summary> /// <param name="messageType">The type of message to construct</param> public SipMessage(SipMessageType messageType, double?version = 1.0, Encoding contentEncoding = null, bool shouldDispse = true) : base((Http.HttpMessageType)messageType, version, contentEncoding, shouldDispse, SipMessage.MessageIdentifier) { }