Пример #1
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);
        }
Пример #2
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);
        }