Ejemplo n.º 1
0
        public override int OnEvent(MsrpEvent e)
        {
            MsrpSession session = e.getSipSession();
            MsrpMessage message = e.getMessage();

            if (session != null && message != null)
            {
                uint id = session.getId();
                //Console.WriteLine("Msrp Event {0} {1}", id, message.getMsrpHeaderValue("Byte-Range"));

                long start, end, total;
                //message.getByteRange(out start, out end, out total);
                //Console.WriteLine("Byte-Range {0}-{1}/{2}", start, end, total);

                //if (message.isRequest())
                // {
                //    uint size = message.getMsrpContentLength();
                //     byte[] bytes = new byte[(int)size];
                //     message.getMsrpContent(bytes, (uint)bytes.Length);
                // }


                if (!message.isRequest() && message.getCode() == 200)
                {
                    if (message.isLastChunck())
                    {
                        session.hangup();
                    }
                }
            }
            return(0);
        }
Ejemplo n.º 2
0
        public static MyMsrpSession TakeIncomingSession(MySipStack sipStack, MsrpSession session, SipMessage message)
        {
            MyMsrpSession msrpSession = null;
            MediaType     mediaType;
            SdpMessage    sdp     = message.getSdpMessage();
            String        fromUri = message.getSipHeaderValue("f");

            if (String.IsNullOrEmpty(fromUri))
            {
                LOG.Error("Invalid fromUri");
                return(null);
            }

            if (sdp == null)
            {
                LOG.Error("Invalid Sdp content");
                return(null);
            }

            String fileSelector = sdp.getSdpHeaderAValue("message", "file-selector");

            mediaType = String.IsNullOrEmpty(fileSelector) ? MediaType.Chat : MediaType.FileTransfer;

            if (mediaType == MediaType.Chat)
            {
                msrpSession = MyMsrpSession.CreateIncomingSession(sipStack, session, mediaType, fromUri);
            }
            else
            {
                String   name       = null;
                String   type       = null;
                String[] attributes = fileSelector.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                foreach (String attribute in attributes)
                {
                    String[] avp = attribute.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    if (avp.Length >= 2)
                    {
                        if (String.Equals(avp[0], "name", StringComparison.InvariantCultureIgnoreCase) && avp[1] != null)
                        {
                            name = avp[1].Replace("\"", String.Empty);
                        }
                        if (String.Equals(avp[0], "type", StringComparison.InvariantCultureIgnoreCase) && avp[1] != null)
                        {
                            type = avp[1];
                        }
                    }
                }
                if (name == null)
                {
                    LOG.Error("Invalid file name");
                    return(null);
                }

                msrpSession          = MyMsrpSession.CreateIncomingSession(sipStack, session, mediaType, fromUri);
                msrpSession.filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), String.Format("{0}/{1}", MyMsrpSession.DESTINATION_FOLDER, name));
                msrpSession.fileType = type;
            }

            return(msrpSession);
        }
Ejemplo n.º 3
0
        public static MyMsrpSession CreateIncomingSession(MySipStack sipStack, MsrpSession session, MediaType mediaType, String remoteUri)
        {
            if (mediaType == MediaType.FileTransfer || mediaType == MediaType.Chat)
            {
                MyMsrpSession msrpSession = new MyMsrpSession(sipStack, session, mediaType, remoteUri);
                MyMsrpSession.sessions.Add(msrpSession.Id, msrpSession);

                return(msrpSession);
            }
            return(null);
        }
Ejemplo n.º 4
0
        public static MyMsrpSession CreateIncomingSession(MySipStack sipStack, MsrpSession session, MediaType mediaType, string remoteUri)
        {
            MyMsrpSession result;

            if (mediaType == MediaType.FileTransfer || mediaType == MediaType.Chat)
            {
                MyMsrpSession msrpSession = new MyMsrpSession(sipStack, session, mediaType, remoteUri);
                MyMsrpSession.sSessions.Add(msrpSession.Id, msrpSession);
                result = msrpSession;
            }
            else
            {
                result = null;
            }
            return(result);
        }
Ejemplo n.º 5
0
 public MyMsrpSession(MySipStack sipStack, MsrpSession session, MediaType mediaType, string remoteUri) : base(sipStack)
 {
     this.mCallback      = new MyMsrpSession.MyMsrpCallback(this);
     this.mMediaType     = mediaType;
     this.remotePartyUri = remoteUri;
     if (session == null)
     {
         this.outgoing = true;
         this.mSession = new MsrpSession(sipStack.WrappedStack, this.mCallback);
     }
     else
     {
         this.outgoing = false;
         this.mSession = session;
         this.mSession.setCallback(this.mCallback);
     }
     base.init();
     base.SigCompId = sipStack.SigCompId;
     this.mSession.addHeader("Subject", "FIXME");
 }
Ejemplo n.º 6
0
        public MyMsrpSession(MySipStack sipStack, MsrpSession session, MediaType mediaType, String remoteUri) : base(sipStack)
        {
            this.callback       = new MyMsrpCallback(this);
            base.mediaType      = mediaType;
            base.remotePartyUri = remoteUri;

            if (session == null)
            {
                base.outgoing = true;
                this.session  = new MsrpSession(sipStack, this.callback);
            }
            else
            {
                base.outgoing = false;
                this.session  = session;
                this.session.setCallback(this.callback);
            }

            // commons
            base.init();

            // SigComp
            base.SigCompId = sipStack.SigCompId;
        }
Ejemplo n.º 7
0
        public static MyMsrpSession TakeIncomingSession(MySipStack sipStack, MsrpSession session, SipMessage message)
        {
            SdpMessage    sdp     = message.getSdpMessage();
            string        fromUri = message.getSipHeaderValue("f");
            MyMsrpSession result;

            if (string.IsNullOrEmpty(fromUri))
            {
                MyMsrpSession.LOG.Error("Invalid fromUri");
                result = null;
            }
            else if (sdp == null)
            {
                MyMsrpSession.LOG.Error("Invalid Sdp content");
                result = null;
            }
            else
            {
                string        fileSelector = sdp.getSdpHeaderAValue("message", "file-selector");
                MediaType     mediaType    = string.IsNullOrEmpty(fileSelector) ? MediaType.Chat : MediaType.FileTransfer;
                MyMsrpSession msrpSession;
                if (mediaType == MediaType.Chat)
                {
                    msrpSession = MyMsrpSession.CreateIncomingSession(sipStack, session, mediaType, fromUri);
                }
                else
                {
                    string type           = null;
                    int    nameIndexStart = fileSelector.IndexOf("name:\"");
                    if (nameIndexStart == -1)
                    {
                        MyMsrpSession.LOG.Error("No name attribute");
                        result = null;
                        return(result);
                    }
                    int nameIndexEnd = fileSelector.IndexOf("\"", nameIndexStart + 6);
                    if (nameIndexEnd == -1)
                    {
                        MyMsrpSession.LOG.Error("Invalid name attribute");
                        result = null;
                        return(result);
                    }
                    string name = fileSelector.Substring(nameIndexStart + 6, nameIndexEnd - nameIndexStart - 6).Trim();
                    fileSelector = fileSelector.Substring(0, nameIndexStart) + fileSelector.Substring(nameIndexEnd + 1, fileSelector.Length - nameIndexEnd - 1);
                    string[] attributes = fileSelector.Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);
                    string[] array      = attributes;
                    for (int i = 0; i < array.Length; i++)
                    {
                        string   attribute = array[i];
                        string[] avp       = attribute.Split(":".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);
                        if (avp.Length >= 2)
                        {
                            if (string.Equals(avp[0], "type", System.StringComparison.InvariantCultureIgnoreCase) && avp[1] != null)
                            {
                                type = avp[1];
                            }
                        }
                    }
                    msrpSession           = MyMsrpSession.CreateIncomingSession(sipStack, session, mediaType, fromUri);
                    msrpSession.mFilePath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), string.Format("{0}/{1}", "Doubango\\SharedContent", name));
                    msrpSession.mFileType = type;
                }
                result = msrpSession;
            }
            return(result);
        }
Ejemplo n.º 8
0
        /*
         * const String REALM = "sip2sip.info";
         * const String USER = "******";
         * const String PASSWORD = "******";
         * const String PROXY_CSCF_IP = "192.168.0.13";
         * const uint PROXY_CSCF_PORT = 5081;
         */

        static void Main(string[] args)
        {
            Boolean success;

            /* Create callbacks */
            sipCallback  = new MySipCallback();
            msrpCallback = new MyMsrpCallback();
            //sipDebugCallback = new MySipDebugCallback();

            /* Create consumers */
            audioConsumer = new MyProxyAudioConsumer();
            videoConsumer = new MyProxyVideoConsumer(tmedia_chroma_t.tmedia_rgb565le);
            /* Create producers */
            audioProducer = new MyProxyAudioProducer();
            videoProducer = new MyProxyVideoProducer(tmedia_chroma_t.tmedia_rgb24);


            /* Create and configure the IMS/LTE stack */
            sipStack = new SipStack(sipCallback, String.Format("sip:{0}", REALM), /*String.Format("{0}@{1}", USER, REALM)*/ USER, String.Format("sip:{0}@{1}", USER, REALM));
            sipStack.setDebugCallback(sipDebugCallback);
            sipStack.addHeader("Allow", "INVITE, ACK, CANCEL, BYE, MESSAGE, OPTIONS, NOTIFY, PRACK, UPDATE, REFER");
            sipStack.addHeader("Privacy", "header; id");
            sipStack.addHeader("P-Access-Network-Info", "ADSL;utran-cell-id-3gpp=00000000");
            sipStack.addHeader("User-Agent", "IM-client/OMA1.0 doubango/v1.0.0");

            /* Do it after stack creation */
            ProxyAudioConsumer.registerPlugin();
            ProxyAudioProducer.registerPlugin();
            ProxyVideoProducer.registerPlugin();
            ProxyVideoConsumer.registerPlugin();


            /* Sets Proxy-CSCF */
            success = sipStack.setProxyCSCF(PROXY_CSCF_IP, PROXY_CSCF_PORT, "udp", "ipv4");
            // STUN
            //sipStack.setSTUNServer("numb.viagenie.ca", 3478);
            //sipStack.setSTUNCred("login", "password");
            // DNS Discovery
            //sipStack.setDnsDiscovery(true);
            /* Starts the stack */
            success = sipStack.start();

            /* Set Password */
            sipStack.setPassword(PASSWORD);

            /* Early IMS */
            sipStack.setEarlyIMS(true);
            /* AMF and Operator Id */
            sipStack.setAMF("0x00FF");
            sipStack.setOperatorId("0xFF0000000000000000000000000000FF");

            // SigComp
            //sipStack.addSigCompCompartment("urn:uuid:2e5fdc76-00be-4314-8202-1116fa82a876");

            //sipStack.setAoR("127.0.0.1", 1234);

            audioConsumer.setActivate(true);
            audioProducer.setActivate(true);
            videoProducer.setActivate(true);
            videoConsumer.setActivate(true);


            /* Send REGISTER */
            regSession = new RegistrationSession(sipStack);
            regSession.addCaps("+g.oma.sip-im");
            regSession.addCaps("+g.3gpp.smsip");
            regSession.addCaps("language", "\"en,fr\"");
            regSession.setExpires(350);
            //regSession.addSigCompCompartment("urn:uuid:2e5fdc76-00be-4314-8202-1116fa82a876");
            regSession.register_();

            Console.ReadLine();


            ActionConfig actionConfig = new ActionConfig();

            actionConfig
            .setMediaString(twrap_media_type_t.twrap_media_msrp, "file-path", "C:\\Users\\root\\Desktop\\Debian.iso")
            //.setMediaString(twrap_media_type_t.twrap_media_msrp, "file-path", "C:\\avatar.png")
            .setMediaString(twrap_media_type_t.twrap_media_msrp, "accept-types", "application/octet-stream")
            .setMediaString(twrap_media_type_t.twrap_media_msrp, "file-disposition", "attachment")
            .setMediaString(twrap_media_type_t.twrap_media_msrp, "file-icon", "cid:[email protected]")
            .setMediaInt(twrap_media_type_t.twrap_media_msrp, "chunck-duration", 500);
            MsrpSession msrpSession = new MsrpSession(sipStack, msrpCallback);

            msrpSession.callMsrp(String.Format("sip:johndoe@{0}", REALM), actionConfig);
            actionConfig.Dispose();

            Console.ReadLine();
            msrpSession.hangup();
            Console.ReadLine();

            //RPMessage rpMessage = SMSEncoder.encodeDeliver(25, SMSC, "123456789", "salut comment tu vas?\n hdjdhfjfhfjhr, ");
            //if (rpMessage != null)
            //{
            //    uint pay_len = rpMessage.getPayloadLength();
            //    if (pay_len > 0)
            //    {
            //        byte[] pay = new byte[pay_len];
            //        rpMessage.getPayload(pay, (uint)pay.Length);

            //        MessagingSession m = new MessagingSession(sipStack);
            //        m.setToUri(String.Format("sip:{0}@{1}", SMSC, REALM));
            //        m.addHeader("Content-Type", "application/vnd.3gpp.sms");
            //        m.addHeader("Content-Transfer-Encoding", "binary");
            //        m.addHeader("P-Asserted-Identity", String.Format("sip:{0}@{1}", USER, REALM));

            //        m.send(pay, (uint)pay.Length);

            //        m.Dispose();
            //    }
            //    rpMessage.Dispose();
            //}

            //Console.ReadLine();



            //String sipUri = sipStack.dnsENUM("E2U+SIP", "+1-800-555-5555", "e164.org");
            //ushort port = 0;
            //String ipAddress = sipStack.dnsNaptrSrv("sip2sip.info", "SIP+D2U", out port);
            //String ipAddress = sipStack.dnsSrv("_sip._udp.sip2sip.info", out port);

            /*ActionConfig actionConfig = new ActionConfig();
             * actionConfig.setMediaInt(twrap_media_type_t.twrap_media_audiovideo, "bandwidth-level", (int)tmedia_bandwidth_level_t.tmedia_bl_medium);
             * callSession = new CallSession(sipStack);
             * callSession.set100rel(true);
             * callSession.setSessionTimer(90, "uas");
             * callSession.setQoS(tmedia_qos_stype_t.tmedia_qos_stype_segmented, tmedia_qos_strength_t.tmedia_qos_strength_optional);
             * callSession.callVideo(String.Format("sip:bob@{0}", REALM), actionConfig);
             * actionConfig.Dispose();*/

            //tcb = new TimerCallback(OnTimer);
            //timer = new Timer(tcb, new AutoResetEvent(false), 0, 20);

            //Console.ReadLine();
            //callSession.sendDTMF(1);
            //Console.ReadLine();
            //callSession.sendDTMF(2);
            //Console.ReadLine();
            //callSession.sendDTMF(11);
            //Console.ReadLine();

            ////Console.ReadLine();
            ////callSession.hold();
            ////Console.ReadLine();
            ////callSession.resume();
            //Console.ReadLine();
            //callSession.hangup();


            ////Thread.Sleep(2000);

            /*RPData rpdata = SMSEncoder.encodeSubmit(25, "+33160188661", "+33660188661", "salut");
             * if (rpdata != null)
             * {
             *  uint pay_len = rpdata.getPayloadLength();
             *  if (pay_len > 0)
             *  {
             *      byte[] pay = new byte[pay_len];
             *      rpdata.getPayload(pay, (uint)pay.Length);
             *
             *      MessagingSession m = new MessagingSession(sipStack);
             *      m.setToUri(String.Format("sip:+33160188661@{0}", REALM));
             *      m.addHeader("Content-Type", "application/vnd.3gpp.sms");
             *      m.addHeader("Transfer-Encoding", "binary");
             *      m.send(pay, (uint)pay.Length);
             *
             *      m.Dispose();
             *  }
             *  rpdata.Dispose();
             * }
             *
             * Console.ReadLine();*/

            ///* Send SUBSCRIBE(reg) */
            //subSession = new SubscriptionSession(sipStack);
            //subSession.addHeader("Event", "reg");
            //subSession.addHeader("Accept", "application/reginfo+xml");
            //subSession.addHeader("Allow-Events", "refer, presence, presence.winfo, xcap-diff, conference");
            //subSession.setExpires(35);
            ////subSession.Subscribe();

            ///* Send MESSAGE */
            //MessagingSession msg = new MessagingSession(sipStack);
            //byte [] content = Encoding.ASCII.GetBytes("Hello World");
            //msg.setToUri(String.Format("sip:{0}@{1}", "alice", REALM));
            //msg.addHeader("NS", "imdn <urn:ietf:params:imdn>");
            //msg.addHeader("imdn.Message-ID", "34jk324j");
            //msg.addHeader("DateTime", "2006-04-04T12:16:49-05:00");
            //msg.addHeader("imdn.Disposition-Notification", "positive-delivery, negative-delivery");
            //msg.addHeader("Content-Type", "text/plain");
            ////msg.Send(content, (uint)content.Length);

            ///* Send OPTIONS */
            //OptionsSession opt = new OptionsSession(sipStack);
            //opt.setToUri(String.Format("sip:{0}@{1}", "hacking_the_aor", REALM));
            //opt.Send();

            Console.ReadLine();

            sipStack.stop();
        }