Exemplo n.º 1
0
        public void Parse_InValidFormats_ExpectToThrowExceptions()
        {
            String[] strings =
            {
                "\r\n\r\n",                                        /*empty message*/
                "  ",                                              /*empty message*/
                "junk\r\n",                                        /*invalid firsline*/
                "\r\n\r\n invalid firsline\r\n",                   /*invalid firsline*/
                "REGISTER sip:192.168.0.1 SIP/2.0\r\n NAME : \r\n" /*fails, first line is folded = ends with NAME*/
            };

            int exceptions = 0;

            foreach (string s in strings)
            {
                try
                {
                    var listenerStub = new SipParserListenerStub();
                    var bytes        = SipFormatter.FormatToBytes(s);
                    new SipParser(listenerStub).Parse(bytes, 0, bytes.Length);
                }
                catch (ParseException e)
                {
                    exceptions++;
                }
            }
            exceptions.Should().Be(strings.Length);
        }
Exemplo n.º 2
0
        public void Parse_ValidFormats_ExpectNotToFail()
        {
            String[] strings =
            {
                "REGISTER sip:192.168.0.1 SIP/2.0\r\nName: Value\r\n\r\n",        /*default format*/
                "REGISTER sip:192.168.0.1 SIP/2.0\r\nNAME : \r\n" +               /*folded line*/
                " Value\r\n\r\n",
                "REGISTER sip:192.168.0.1 SIP/2.0\r\nNAME: Value, Value\r\n\r\n", /*comma separated values on same line*/
                "REGISTER sip:192.168.0.1 SIP/2.0\r\nName    :Value\r\n\r\n"      /*support white spaces after name*/
                //"REGISTER sip:192.168.0.1 SIP/2.0\r\nNAME: Value\r\n\r\n",
                //"REGISTER sip:192.168.0.1 SIP/2.0\r\nname:  Value\r\n\r\n",
                //"REGISTER sip:192.168.0.1 SIP/2.0\r\n naME :  Value\r\n\r\n", fails because first line is folded line and so does not end with SIP/2.0
            };

            foreach (string s in strings)
            {
                var listenerStub = new SipParserListenerStub();
                var bytes        = SipFormatter.FormatToBytes(s);
                new SipParser(listenerStub).Parse(bytes, 0, bytes.Length);

                listenerStub.OnRequestExecuteReceived.Should().NotBeNull();
                listenerStub.OnResponseExecuteReceived.Should().BeNull();
                listenerStub.OnCompleteExecuteReceived.Should().BeTrue();
                listenerStub.OnHeaderExecuteReceived.Should().NotBeEmpty();
                listenerStub.OnHeaderExecuteReceived["Name"].Should().NotBeEmpty();
            }
        }
Exemplo n.º 3
0
        private void _btnSend_Click(object sender, EventArgs e)
        {
            if (_txtMessage.Text == string.Empty)
            {
                MessageBox.Show("Can not send an empty message");
            }

            UdpClient udpClient = new UdpClient(AddressFamily.InterNetwork);
            var       bytes     = SipFormatter.FormatToBytes(_txtMessage.Text);

            udpClient.Send(bytes, bytes.Length, SipUtil.ParseIpEndPoint(_txtSendTo.Text));
        }
Exemplo n.º 4
0
        protected override void When()
        {
            var f = new SipStack();
            var messageFacttory = f.CreateMessageFactory();
            var headerFactory   = f.CreateHeaderFactory();

            foreach (string message in _messages)
            {
                var parserContext = new SipParserContext(messageFacttory, headerFactory);
                parserContext.ParseCompleted += (s, e) => _subjectFoldedRequest.Add((SipRequest)e.Message);
                parserContext.Parse(SipFormatter.FormatToBytes(message));
            }
        }
        protected override void When()
        {
            var bytes = SipFormatter.FormatToBytes(_knownRegisterRequestString);

            _sipRequest = _parser.Parse(new DatagramPacketBuilder().WithDataBytes(bytes).Build()) as SipRequest;
        }