Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        //private void Test_Click_1(object sender, RoutedEventArgs e)//测试用
        //{
        //    XmlDocument Request;
        //    Socket exoSocket;
        //    SipSocket temp;
        //    string[] result = new string[10];
        //    System.Timers.Timer timer = new System.Timers.Timer(2000);
        //    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;
        //    }
        //    /*----------------------------分割线-----------------------------*/
        //    temp = SipSocket.FindSipSocket(exoSocket);
        //    Request = InterfaceC.StopMediaReq("0000000000000000", "6101010000000001", "0");//提取参数并转为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]);

        //}

        private void Test_Click_1(object sender, RoutedEventArgs e)//测试用
        {
            byte[]    recv   = new byte[2048];
            string[]  result = new string[10];
            SipSocket temp   = SipSocket.FindSipSocket(testsocket);

            System.Timers.Timer timer = new System.Timers.Timer(2000);
            SipSocket.CleanResult(testsocket);
            switch (Combo.SelectionBoxItem.ToString())
            {
            case "StartMediaReq":
                temp.SendRequest(InterfaceC.StartMediaReq("6101010000000000", "6101010000000001", "63", "1", "0", "", "", "1"));
                break;

            case "StopMediaReq":
                temp.SendRequest(InterfaceC.StopMediaReq("0000000000000000", "6101010000000001", "0"));
                break;

            case "QueryHistoryFiles":
                temp.SendRequest(InterfaceC.QueryHistoryFiles("0000000000000000", "6101010000000001", "0", "1111", "2015-03-22 12:22:33", "2015-03-22 12:42:33"));
                break;

            case "StartPlayBack":
                temp.SendRequest(InterfaceC.StartPlayBack("0000000000000000", "6101010000000001", "0", "2015-03-22 12:22:33", "2015-03-22 12:42:33", 0, "192.168.1.1", "15000", 1, 1));
                break;

            case "ControlFileBack":
                temp.SendRequest(InterfaceC.ControlFileBack("00000000000", "00038478", "UP", 0));
                break;

            case "StartHisLoad":
                temp.SendRequest(InterfaceC.StartHisLoad("0000000000000000", "6101010000000001", "0", "2015-03-22 12:22:33", "2015-03-22 12:42:33", 0, "192.168.1.1", "15000", 1, 1));
                break;

            case "ReqCamResState":
                string[] str = { "000000", "1111111", "222222" };
                temp.SendRequest(InterfaceC.ReqCamResState("0000000000000000", str, 1));
                break;

            case "GetUserCurState":
                temp.SendRequest(InterfaceC.GetUserCurState("0000000000000000", "6101010000000001"));
                break;

            case "SetUserCamManage":
                string[] cameId = { "00000", "111111" }, id = { "222222", "333333" };
                temp.SendRequest(InterfaceC.SetUserCamManage("0000000000000000", "6101010000000001", 0, "2015-03-22 12:22:33", "2015-03-22 12:42:33", "2015-03-22 11:42:33", cameId, 2, id, 2));
                break;

            case "AlarmResSubscribe":
                string[] type = { "666666", "4444444" }, id_0 = { "00000", "11111" };
                temp.SendRequest(InterfaceC.AlarmResSubscribe("0000000000000000", "6101010000000001", 0, id_0, type, 2));
                break;

            default:
                break;
            }

            result = WaitForResult(testsocket, timer, 2000);

            if (result != null)
            {
                for (int k = 0; k < result.Length; k++)
                {
                    Console.WriteLine(result[k]);
                }
            }
            //XXX.Send(InterfaceC.StartMediaReq("127.0.0.1", "12000", "6100011201000102", "6100011201000102", "1", "1", "0", "", "", "1"));
        }
Ejemplo n.º 3
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();
            }
        }