Exemple #1
0
        void osipCallClose(eXosip.Event eXosipEvent)
        {
            IntPtr      ptr;
            XmlDocument Request;
            Socket      exoSocket;
            SipSocket   temp;

            osip.From pFrom = osip.Message.GetFrom(eXosipEvent.request);
            osip.From pTo   = osip.Message.GetTo(eXosipEvent.request);
            osip.URI  uri   = (osip.URI)Marshal.PtrToStructure(osip.From.GetURL(pTo.url), typeof(osip.URI));
            string    name  = osip.URI.ToString(pTo.url);
            string    id    = name.Substring(4, name.IndexOf('@') - 4);

            if ((exoSocket = SipSocket.FindSocket(id.Substring(0, 6))) == null)
            {
                eXosip.Call.SendAnswer(eXosipEvent.tid, 404, IntPtr.Zero);
                eXosip.Unlock();
                return;
            }
            /*----------------------------分割线-----------------------------*/
            Request = InterfaceC.StopMediaReq("0000000000000000", "6101010000000001", "0");//提取参数并转为C类接口格式

            temp = SipSocket.FindSipSocket(exoSocket);
            try
            {
                temp.SendRequest(Request);
            }
            catch (SocketException ex)
            {
                System.Console.WriteLine(ex);
            }

            SipSocket.CleanResult(exoSocket);
        }
Exemple #2
0
        void osipMessage(eXosip.Event eXosipEvent)
        {
            IntPtr      ptr;
            XmlDocument TempDoc = new XmlDocument();
            XmlDocument Request;
            Socket      exoSocket;
            SipSocket   temp;

            ptr = osip.Message.GetContentType(eXosipEvent.request);
            if (ptr == IntPtr.Zero)
            {
                return;
            }
            osip.ContentType content = (osip.ContentType)Marshal.PtrToStructure(ptr, typeof(osip.ContentType));
            ptr = osip.Message.GetBody(eXosipEvent.request);
            if (ptr == IntPtr.Zero)
            {
                return;
            }

            osip.From pTo      = osip.Message.GetTo(eXosipEvent.request);
            osip.From pFrom    = osip.Message.GetFrom(eXosipEvent.request);
            osip.URI  uriTo    = (osip.URI)Marshal.PtrToStructure(osip.From.GetURL(pTo.url), typeof(osip.URI));
            osip.URI  uriFrom  = (osip.URI)Marshal.PtrToStructure(osip.From.GetURL(pFrom.url), typeof(osip.URI));
            string    name     = osip.URI.ToString(pTo.url);
            string    name2    = osip.URI.ToString(pFrom.url);
            string    resId    = name.Substring(4, name.IndexOf('@') - 4);
            string    userCode = name2.Substring(4, name2.IndexOf('@') - 4);
            string    userId   = resId.Substring(0, 10) + userCode;

            if ((exoSocket = SipSocket.FindSocket(resId.Substring(0, 6))) == null)
            {
                eXosip.Call.SendAnswer(eXosipEvent.tid, 404, IntPtr.Zero);
                eXosip.Unlock();
                return;
            }

            osip.Body data = (osip.Body)Marshal.PtrToStructure(ptr, typeof(osip.Body));
            if (Marshal.PtrToStringAnsi(content.type) != "application" ||
                Marshal.PtrToStringAnsi(content.subtype) != "xml")
            {
                return;
            }
            string xml = Marshal.PtrToStringAnsi(data.body);

            Console.Write(xml);
            /*----------------------------分割线-----------------------------*/
            TempDoc.LoadXml(xml);
            //SipSocket.CleanResult(exoSocket);
            //temp = SipSocket.FindSipSocket(exoSocket);
            //temp.Send(Request);
        }
Exemple #3
0
        void Snoop()
        {
            eXosip.Init();
            eXosip.ListenAddr(ProtocolType.Udp, null, 5060, AddressFamily.InterNetwork, 0);
            while (true)
            {
                IntPtr je = eXosip.Event.Wait(0, 1);
                if (je == IntPtr.Zero)
                {
                    continue;
                }
                eXosip.Lock();
                eXosip.AutomaticAction();
                eXosip.Unlock();
                eXosip.Event eXosipEvent = (eXosip.Event)Marshal.PtrToStructure(je, typeof(eXosip.Event));
                Console.WriteLine(eXosipEvent.textinfo);
                switch (eXosipEvent.type)
                {
                case eXosip.EventType.EXOSIP_CALL_INVITE:
                    osipCallInvite(eXosipEvent);
                    break;

                case eXosip.EventType.EXOSIP_CALL_MESSAGE_NEW:
                    osipCallMessage(eXosipEvent);
                    break;

                case eXosip.EventType.EXOSIP_MESSAGE_NEW:
                    osipMessage(eXosipEvent);
                    break;

                case eXosip.EventType.EXOSIP_CALL_CLOSED:
                    osipCallClose(eXosipEvent);
                    break;

                default:
                    break;
                }
                eXosip.Event.Free(je);
                Thread.Sleep(100);
            }
            eXosip.Quit();
        }
Exemple #4
0
        void osipCallMessage(eXosip.Event eXosipEvent)
        {
            IntPtr      ptr;
            XmlDocument TempDoc = new XmlDocument();
            XmlDocument Request;
            Socket      exoSocket;
            SipSocket   temp;

            string[]            result = new string[10];
            System.Timers.Timer timer  = new System.Timers.Timer(2000);
            ptr = osip.Message.GetContentType(eXosipEvent.request);
            if (ptr == IntPtr.Zero)
            {
                return;
            }
            osip.ContentType content = (osip.ContentType)Marshal.PtrToStructure(ptr, typeof(osip.ContentType));
            ptr = osip.Message.GetBody(eXosipEvent.request);
            if (ptr == IntPtr.Zero)
            {
                return;
            }

            osip.From pTo      = osip.Message.GetTo(eXosipEvent.request);
            osip.From pFrom    = osip.Message.GetFrom(eXosipEvent.request);
            osip.URI  uriTo    = (osip.URI)Marshal.PtrToStructure(osip.From.GetURL(pTo.url), typeof(osip.URI));
            osip.URI  uriFrom  = (osip.URI)Marshal.PtrToStructure(osip.From.GetURL(pFrom.url), typeof(osip.URI));
            string    name     = osip.URI.ToString(pTo.url);
            string    name2    = osip.URI.ToString(pFrom.url);
            string    resId    = name.Substring(4, name.IndexOf('@') - 4);
            string    userCode = name2.Substring(4, name2.IndexOf('@') - 4);
            string    userId   = resId.Substring(0, 10) + userCode;

            if ((exoSocket = SipSocket.FindSocket(resId.Substring(0, 6))) == null)
            {
                eXosip.Call.SendAnswer(eXosipEvent.tid, 404, IntPtr.Zero);
                eXosip.Unlock();
                return;
            }

            osip.Body data = (osip.Body)Marshal.PtrToStructure(ptr, typeof(osip.Body));
            if (Marshal.PtrToStringAnsi(content.type) != "application" ||
                Marshal.PtrToStringAnsi(content.subtype) != "xml")
            {
                return;
            }
            string xml = Marshal.PtrToStringAnsi(data.body);

            Console.Write(xml);
            /*----------------------------分割线-----------------------------*/
            TempDoc.LoadXml(xml);
            temp    = SipSocket.FindSipSocket(exoSocket);
            Request = InterfaceC.CallMessageTranslate(TempDoc, resId, userId);//提取参数并转为C类接口格式
            SipSocket.CleanResult(exoSocket);
            temp.SendRequest(Request);
            result = WaitForResult(testsocket, timer, 2000);

            if (result != null)
            {
                for (int k = 0; k < result.Length; k++)
                {
                    Console.WriteLine(result[k]);
                }
            }
            temp = SipSocket.FindSipSocket(exoSocket);
            temp.SendRequest(Request);
        }
Exemple #5
0
        private void osipCallInvite(eXosip.Event eXosipEvent)
        {
            Socket exoSocket;

            eXosip.Lock();
            byte[]      recv    = new byte[2048];
            XmlDocument Request = new XmlDocument();;
            SipSocket   temp;

            System.Timers.Timer timer  = new System.Timers.Timer(2000);
            string[]            result = new string[10];
            eXosip.Call.SendAnswer(eXosipEvent.tid, 180, IntPtr.Zero);
            IntPtr sdp = eXosip.GetRemoteSdp(eXosipEvent.did);

            if (sdp == IntPtr.Zero)
            {
                eXosip.Call.SendAnswer(eXosipEvent.tid, 400, IntPtr.Zero);
                eXosip.Unlock();
                return;
            }

            osip.From pTo      = osip.Message.GetTo(eXosipEvent.request);
            osip.From pFrom    = osip.Message.GetFrom(eXosipEvent.request);
            osip.URI  uriTo    = (osip.URI)Marshal.PtrToStructure(osip.From.GetURL(pTo.url), typeof(osip.URI));
            osip.URI  uriFrom  = (osip.URI)Marshal.PtrToStructure(osip.From.GetURL(pFrom.url), typeof(osip.URI));
            string    name     = osip.URI.ToString(pTo.url);
            string    name2    = osip.URI.ToString(pFrom.url);
            string    resId    = name.Substring(4, name.IndexOf('@') - 4);
            string    userCode = name2.Substring(4, name2.IndexOf('@') - 4);
            string    userId   = resId.Substring(0, 10) + userCode;

            if ((exoSocket = SipSocket.FindSocket(resId.Substring(0, 6))) == null)
            {
                eXosip.Call.SendAnswer(eXosipEvent.tid, 404, IntPtr.Zero);
                eXosip.Unlock();
                return;
            }

            string sessionname = osip.SdpMessage.GetSessionName(sdp);

            //以下的接口中的数据均为伪造,未测试版本,缺失提取Xml信息的步骤
            if (sessionname == "RealTime")
            {
                Request = InterfaceC.StartMediaReq(resId, userId, "63", "1", "0", "", "", "1");
            }
            else if (sessionname == "PlayBack")
            {
                Request = InterfaceC.StartPlayBack(resId, userId, "63", "2015-03-22 22:33:22", "2015-03-22 23:44:22", 0, "192.168.1.1", "15000", 1, 0);
            }
            else if (sessionname == "DownLoad")
            {
                Request = InterfaceC.StartHisLoad(resId, userId, "63", "2015-03-22 22:33:22", "2015-03-22 23:44:22", 0, "192.168.1.1", "15000", 1, 0);//测试
            }
            else if (sessionname == "PlayBack")
            {
                Request = InterfaceC.StartPlayBack(resId, userId, "63", "2015-03-22 22:33:22", "2015-03-22 23:44:22", 0, "192.168.1.1", "15000", 1, 0);
            }
            else if (sessionname == "DownLoad")
            {
                Request = InterfaceC.StartHisLoad(resId, userId, "63", "2015-03-22 22:33:22", "2015-03-22 23:44:22", 0, "192.168.1.1", "15000", 1, 0);//测试
            }

            temp = SipSocket.FindSipSocket(exoSocket);
            temp.SendRequest(Request);
            timer.Elapsed += new System.Timers.ElapsedEventHandler(Tick);
            timer.Enabled  = true;
            while (true)
            {
                Request = InterfaceC.StartMediaReq(resId, userId, "63", "1", "0", "", "", "1");
            }


            temp = SipSocket.FindSipSocket(exoSocket);
            SipSocket.CleanResult(exoSocket);
            temp.SendRequest(Request);
            result = WaitForResult(testsocket, timer, 2000);

            if (result != null)
            {
                for (int k = 0; k < result.Length; k++)
                {
                    Console.WriteLine(result[k]);
                }
            }
            else
            {
                eXosip.Call.SendAnswer(eXosipEvent.tid, 404, IntPtr.Zero);
                eXosip.Unlock();
                return;
            }
            string sessionId      = osip.SdpMessage.GetSessionId(sdp);
            string sessionVersion = osip.SdpMessage.GetSessionVersion(sdp);
            IntPtr answer         = eXosip.Call.BuildAnswer(eXosipEvent.tid, 200);

            if (answer != IntPtr.Zero)
            {
                string tmp = string.Format(
                    "v=0\r\n" +
                    "o={0} {1} {2} IN IP4 {3}\r\n" +
                    "s={5}\r\n" +
                    "c=IN IP4 {3}\r\n" +
                    "t=0 0\r\n" +
                    "a=sendonly\r\n" +
                    "m=video {4} TCP H264\r\n" +
                    "a=setup:passive\r\n" +
                    "a=connection:new\r\n" +
                    "m=audio {4} TCP PCMA\r\n" +
                    "a=setup:passive\r\n" +
                    "a=connection:new\r\n",
                    resId,
                    sessionId,
                    sessionVersion,
                    result[1],
                    result[2],
                    sessionname);
                osip.Message.SetBody(answer, tmp);
                osip.Message.SetContentType(answer, "application/sdp");
                eXosip.Call.SendAnswer(eXosipEvent.tid, 200, answer);
                eXosip.Unlock();
            }
        }