public AuFileAssembler(string auFilename, FileStreamAssemblerList fileStreamAssemblerList, FiveTuple fiveTuple, FileStreamTypes fileStreamType, long initialFrameNumber, DateTime startTime, Encoding auEncoding, uint sampleRate = 8000) :
     base(fileStreamAssemblerList, fiveTuple, true, fileStreamType, auFilename, "/", fileStreamType.ToString() + " " + fiveTuple.ToString(), initialFrameNumber, startTime)
 {
     this.sampleRate = sampleRate;
     this.AuEncoding = auEncoding;
     //unknown file size
     this.FileContentLength         = -1;
     this.FileSegmentRemainingBytes = -1;
 }
 public WavFileAssembler(string wavFilename, FileStreamAssemblerList fileStreamAssemblerList, FiveTuple fiveTuple, FileStreamTypes fileStreamType, long initialFrameNumber, DateTime startTime, uint sampleRate = 8000) :
     base(fileStreamAssemblerList, fiveTuple, true, fileStreamType, wavFilename, "/", fileStreamType.ToString() + " " + fiveTuple.ToString(), initialFrameNumber, startTime)
 {
     if (fileStreamType == FileStreamTypes.RTP)
     {
         this.FileContentLength         = -1;
         this.FileSegmentRemainingBytes = -1;
         //this.fileStreamAssemblerList.Add(assembler);
     }
     this.sampleRate = sampleRate;
 }
示例#3
0
        /*
         * public AudioStream(NetworkHost sourceHost, NetworkHost destinationHost, AudioFormat format,
         *  FileTransfer.FileStreamAssemblerList fileStreamAssemblerList, FiveTuple fiveTuple, long initialFrameNumber) {
         */
        public AudioStream(NetworkHost sourceHost, NetworkHost destinationHost, PacketParser.PacketHandlers.RtpPacketHandler.RtpPayloadType format, FileTransfer.FileStreamAssemblerList fileStreamAssemblerList, FiveTuple fiveTuple, long initialFrameNumber)
        {
            this.SourceHost      = sourceHost;
            this.DestinationHost = destinationHost;
            this.Format          = format;
            //this.Assembler = assembler;
            this.fileStreamAssemblerList = fileStreamAssemblerList;
            this.FiveTuple          = fiveTuple;
            this.initialFrameNumber = initialFrameNumber;

            this.sampleCount = 0;
            this.tempFS      = new System.IO.FileStream(System.IO.Path.GetTempFileName(), System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite, System.IO.FileShare.Read, 262144);
            this.sampleInfo  = new List <SampleChunkInfo>();
        }
        /*
         * public AudioStream(NetworkHost sourceHost, NetworkHost destinationHost, AudioFormat format,
         *  FileTransfer.FileStreamAssemblerList fileStreamAssemblerList, FiveTuple fiveTuple, long initialFrameNumber) {
         */
        public AudioStream(NetworkHost sourceHost, NetworkHost destinationHost, PacketParser.PacketHandlers.RtpPacketHandler.RtpPayloadType format, FileTransfer.FileStreamAssemblerList fileStreamAssemblerList, FiveTuple fiveTuple, long initialFrameNumber)
        {
            this.SourceHost      = sourceHost;
            this.DestinationHost = destinationHost;
            this.Format          = format;
            //this.Assembler = assembler;
            this.fileStreamAssemblerList = fileStreamAssemblerList;
            this.FiveTuple          = fiveTuple;
            this.initialFrameNumber = initialFrameNumber;
            this.sampleCount        = 0;
            //The GetTempFileName method will raise an IOException if it is used to create more than 65535 files without deleting previous temporary files.
            //The GetTempFileName method will raise an IOException if no unique temporary file name is available.To resolve this error, delete all unneeded temporary files.
            this.tempFileName = System.IO.Path.GetTempFileName();
            FileTransfer.FileStreamAssemblerList.TempFileHandlers.Add(this);

            this.tempFileStream = new System.IO.FileStream(tempFileName, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite, System.IO.FileShare.Read, 262144);
            this.sampleInfo     = new List <SampleChunkInfo>();
        }
示例#5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sourceHost"></param>
        /// <param name="sourcePort"></param>
        /// <param name="destinationHost"></param>
        /// <param name="destinationPort"></param>
        /// <param name="tcpTransfer">True=TCP, False=UDP</param>
        /// <param name="fileStreamType"></param>
        /// <param name="filename">for example "image.gif"</param>
        /// <param name="fileLocation">for example "/images", empty string for root folder</param>
        internal FileStreamAssembler(FileStreamAssemblerList parentAssemblerList, NetworkHost sourceHost, ushort sourcePort, NetworkHost destinationHost, ushort destinationPort, bool tcpTransfer, FileStreamTypes fileStreamType, string filename, string fileLocation, int fileContentLength, int fileSegmentRemainingBytes, string details, string extendedFileId, int initialFrameNumber, DateTime timestamp)
        {
            this.parentAssemblerList       = parentAssemblerList;
            this.sourceHost                = sourceHost;
            this.sourcePort                = sourcePort;
            this.destinationHost           = destinationHost;
            this.destinationPort           = destinationPort;
            this.tcpTransfer               = tcpTransfer;
            this.fileStreamType            = fileStreamType;
            this.fileContentLength         = fileContentLength;//this one can not be set already when the client requests the file...so it has to be changed later
            this.fileSegmentRemainingBytes = fileSegmentRemainingBytes;
            this.details            = details;
            this.contentEncoding    = Packets.HttpPacket.ContentEncodings.Identity;//default
            this.isActive           = false;
            this.extendedFileId     = extendedFileId;
            this.initialFrameNumber = initialFrameNumber;
            this.timestamp          = timestamp;

            this.filename     = filename;
            this.fileLocation = fileLocation;



            //Sigh I just hate the limitation on file and folder length.
            //See: http://msdn2.microsoft.com/en-us/library/aa365247.aspx
            //Or: http://blogs.msdn.com/bclteam/archive/2007/02/13/long-paths-in-net-part-1-of-3-kim-hamilton.aspx

            //see if there is any fileLocation info in the filename and move it to the fileLocation
            FixFilenameAndLocation(ref this.filename, ref this.fileLocation);



            this.assembledByteCount    = 0;
            this.tcpPacketBufferWindow = new SortedList <uint, byte[]>();

            if (isActive)
            {
                this.fileStream = new System.IO.FileStream(GetFilePath(true), System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite);
            }
            else
            {
                this.fileStream = null;
            }
        }
示例#6
0
        internal PartialFileAssembler(FileStreamAssembler.FileAssmeblyRootLocation fileAssmeblyRootLocation, FiveTuple fiveTuple, bool transferIsClientToServer, FileStreamTypes fileStreamType, string fileLocation, string filename, FileStreamAssemblerList parentAssemblerList, string extendedFileId, long totalFileSize, long initialFrameNumber, string serverHostname)
        {
            this.fileAssmeblyRootLocation = fileAssmeblyRootLocation;

            /*
             * this.tcpTransfer = tcpTransfer;
             * this.sourceHost = sourceHost;
             * this.destinationHost = destinationHost;
             * this.sourcePort = sourcePort;
             * this.destinationPort = destinationPort;
             */
            this.fiveTuple = fiveTuple;
            this.transferIsClientToServer = transferIsClientToServer;
            this.fileStreamType           = fileStreamType;
            this.fileLocation             = fileLocation;
            this.filename            = filename;
            this.parentAssemblerList = parentAssemblerList;
            this.extendedFileId      = extendedFileId;
            this.totalFileSize       = totalFileSize;
            //this.originalLocation = originalLocation;
            this.filePartList       = new SortedList <long, ReconstructedFile>();
            this.initialFrameNumber = initialFrameNumber;
            this.serverHostname     = serverHostname;
        }
示例#7
0
 FileSegmentAssemblerHandler(string fileOutputDirectory, FileStreamAssemblerList fileStreamAssemblerList) {
     this.fileOutputDirectory = fileOutputDirectory;
     this.fileStreamAssemblerList = fileStreamAssemblerList;
     this.assemblerList = new PopularityList<string, FileSegmentAssembler>(100);//100 simultaneous partial downloads allowed
 }
示例#8
0
        private static string GetFilePath(bool tempCachePath, bool tcpTransfer, System.Net.IPAddress sourceIp, System.Net.IPAddress destinationIp, ushort sourcePort, ushort destinationPort, FileStreamTypes fileStreamType, string fileLocation, string filename, FileStreamAssemblerList parentAssemblerList, string extendedFileId)
        {
            //sanitize filename
            if (filename.IndexOfAny(System.IO.Path.GetInvalidFileNameChars()) >= 0)
            {
                foreach (char c in System.IO.Path.GetInvalidFileNameChars())
                {
                    filename.Replace(c, '_');
                }
            }

            //sanitize file location
            fileLocation = fileLocation.Replace("..", "_");//just to ensure that no file is written to a parent directory
            if (fileLocation.IndexOfAny(System.IO.Path.GetInvalidPathChars()) >= 0)
            {
                foreach (char c in System.IO.Path.GetInvalidPathChars())
                {
                    fileLocation.Replace(c, '_');
                }
            }

            string filePath;
            string protocolString;

            if (fileStreamType == FileStreamTypes.HttpGetNormal || fileStreamType == FileStreamTypes.HttpGetChunked)
            {
                protocolString = "HTTP";
            }
            else if (fileStreamType == FileStreamTypes.SMB)
            {
                protocolString = "SMB";
            }
            else if (fileStreamType == FileStreamTypes.TFTP)
            {
                protocolString = "TFTP";
            }
            else if (fileStreamType == FileStreamTypes.TlsCertificate)
            {
                protocolString = "TLS_Cert";
            }
            else if (fileStreamType == FileStreamTypes.FTP)
            {
                protocolString = "FTP";
            }
            else if (fileStreamType == FileStreamTypes.HttpPostMimeMultipartFormData)
            {
                protocolString = "MIME_form-data";
            }
            else if (fileStreamType == FileStreamTypes.HttpPostMimeFileData)
            {
                protocolString = "MIME_file-data";
            }
            else if (fileStreamType == FileStreamTypes.OscarFileTransfer)
            {
                protocolString = "OSCAR";
            }
            else if (fileStreamType == FileStreamTypes.SMTP)
            {
                protocolString = "SMTP";
            }
            else
            {
                throw new Exception("Not implemented yet");
            }

            string transportString;

            if (tcpTransfer)
            {
                transportString = "TCP";
            }
            else
            {
                transportString = "UDP";
            }



            if (tempCachePath)
            {
                filePath = "cache/" + sourceIp.ToString().Replace(':', '-') + "_" + transportString + sourcePort.ToString() + " - " + destinationIp.ToString().Replace(':', '-') + "_" + transportString + destinationPort.ToString() + "_" + protocolString + extendedFileId + ".txt";//with extendedFileId 2011-04-18
                //filePath = "cache/" + sourceIp.ToString().Replace(':', '-') + "_" + transportString + sourcePort.ToString() + " - " + destinationIp.ToString().Replace(':', '-') + "_" + transportString + destinationPort.ToString() + "_" + protocolString + ".txt";//without extendedFileId
            }
            else
            {
                filePath = sourceIp.ToString().Replace(':', '-') + "/" + protocolString + " - " + transportString + " " + sourcePort.ToString() + fileLocation + "/" + filename;
                try {
                    System.IO.Path.GetDirectoryName(filePath);
                }
                catch {
                    //something could be wrong with the path.. so let's replace it with something that should work better
                    //Examples of things that can go wrong is that the file or directory has a reserved name (like COM2, CON or LPT1) as shown here:
                    //http://www.ureader.com/msg/144639432.aspx
                    //http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx
                    filePath = sourceIp.ToString().Replace(':', '-') + "/" + protocolString + " - " + transportString + " " + sourcePort.ToString() + "/" + System.IO.Path.GetRandomFileName();
                }
            }


            //filePath=System.IO.Path.GetDirectoryName(parentAssemblerList.FileOutputFolder)+"\\"+filePath;
            filePath = parentAssemblerList.FileOutputDirectory + System.IO.Path.DirectorySeparatorChar + filePath;

            if (System.IO.Path.DirectorySeparatorChar != '/' && filePath.Contains("/"))
            {
                filePath = filePath.Replace('/', System.IO.Path.DirectorySeparatorChar);
            }

            /*if(filePath.Length>=248)
             *  filePath="\\\\?\\"+filePath;*/

            if (!tempCachePath && System.IO.File.Exists(filePath))
            {
                //change filename to avoid overwriting previous files
                int    iterator = 1;
                string filePathPrefix;
                string filePathSuffix;                             //including the "." as in ".txt"
                //now, find the breakpoint in filePath where "[1]" should be inserted
                int extentionPosition = filePath.LastIndexOf('.'); //The index position of value if that character is found, or -1 if it is not
                int filenamePosition  = filePath.LastIndexOf(System.IO.Path.DirectorySeparatorChar);

                if (extentionPosition < 0)
                {
                    filePathPrefix = filePath;
                    filePathSuffix = "";
                }
                else if (extentionPosition > filenamePosition)
                {
                    filePathPrefix = filePath.Substring(0, extentionPosition);
                    filePathSuffix = filePath.Substring(extentionPosition);
                }
                else
                {
                    filePathPrefix = filePath;
                    filePathSuffix = "";
                }

                string uniqueFilePath = filePathPrefix + "[" + iterator + "]" + filePathSuffix;
                while (System.IO.File.Exists(uniqueFilePath))
                {
                    iterator++;
                    uniqueFilePath = filePathPrefix + "[" + iterator + "]" + filePathSuffix;
                }
                filePath = uniqueFilePath;
            }

            return(filePath);
        }
示例#9
0
 internal FileStreamAssembler(FileStreamAssemblerList parentAssemblerList, NetworkHost sourceHost, ushort sourcePort, NetworkHost destinationHost, ushort destinationPort, bool tcpTransfer, FileStreamTypes fileStreamType, string filename, string fileLocation, string details, string extendedFileId, int initialFrameNumber, DateTime timestamp)
     :
     this(parentAssemblerList, sourceHost, sourcePort, destinationHost, destinationPort, tcpTransfer, fileStreamType, filename, fileLocation, 0, 0, details, extendedFileId, initialFrameNumber, timestamp)  //shall I maybe have -1 as fileContentLength???
 {
 }