예제 #1
0
        private void CreateFailedSink(HTTPSession ss)
        {
            lock (TagQueue)
            {
                while (TagQueue.Count > 0)
                {
                    StateData sd = (StateData)TagQueue.Dequeue();
                    EventLogger.Log(this, EventLogEntryType.Error, "Connection Attempt to [" + sd.Dest + "] Refused/Failed");

                    object Tag = sd.Tag;
                    if (sd.HeaderCB != null)
                    {
                        sd.HeaderCB(this, ss, null, null, Tag);
                    }
                    else
                    {
                        if (OnResponse != null)
                        {
                            OnResponse(this, null, Tag);
                        }
                    }
                }
                s = null;
            }
        }
예제 #2
0
 private void RequestAnsweredSink(HTTPSession ss)
 {
     lock (TagQueue)
     {
         if (!ReceivedFirstResponse)
         {
             ReceivedFirstResponse = true;
             IEnumerator en = TagQueue.GetEnumerator();
             while (en.MoveNext())
             {
                 StateData sd = (StateData)en.Current;
                 try
                 {
                     if (ProxySetting == null)
                     {
                         ss.Send(sd.Request);
                     }
                     else
                     {
                         HTTPMessage pr = (HTTPMessage)sd.Request.Clone();
                         pr.DirectiveObj = "http://" + sd.Dest.ToString() + pr.DirectiveObj;
                         pr.Version      = "1.0";
                         ss.Send(pr);
                     }
                 }
                 catch (Exception ex)
                 {
                     OpenSource.Utilities.EventLogger.Log(ex);
                 }
             }
         }
     }
 }
예제 #3
0
        private void WebSession_OnStreamDone(HTTPSession sender, Stream streamObject)
        {
            sender.OnStreamDone -= WebSession_OnStreamDone;
            AllowSystemStandBy();

            try
            {
                if (streamObject != null)
                {
                    sender.CloseStreamObject(streamObject);
                    streamObject.Dispose();
                }

                string lastPlayedFile = sender.StateObject as string;
                if (!String.IsNullOrEmpty(lastPlayedFile))
                {
                    string nextFile = GetNextFile(sender.Remote.Address, lastPlayedFile);
                    if (!String.IsNullOrEmpty(nextFile))
                    {
                        // Enchain the audio files on the Freebox V5
                        SendStreamObject(sender, null, String.Format("0/{0}/1", nextFile));
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.WriteException(ex);
            }
        }
예제 #4
0
        private void ReceiveSink(HTTPSession sender, HTTPMessage msg)
        {
            StateData sd  = (StateData)sender.StateObject;
            object    Tag = sd.Tag;

            if (msg.Version == "1.0" || msg.Version == "0.9")
            {
                sender.Close();
            }
            else
            {
                if (msg.GetTag("Connection").ToUpper() == "CLOSE")
                {
                    sender.Close();
                }
            }


            if (OnResponse != null)
            {
                OnResponse(this, msg, Tag);
            }
            // If I don't set this to null, this holds a strong reference, resulting in
            // possible memory leaks
            sender.StateObject = null;
            lock (TagQueue)
            {
                if (TagQueue.Count == 0)
                {
                    this.IdleTimeout = true;
                    KeepAliveTimer.Add(this.GetHashCode(), 10);
                }
            }
        }
예제 #5
0
        private void SendErrorMessage(HTTPSession webSession, Stream stream)
        {
            try
            {
                if (stream != null)
                {
                    webSession.CloseStreamObject(stream);
                    stream.Dispose();
                    stream = null;
                }

                HTTPMessage error = new HTTPMessage();
                error.StatusCode   = 404;
                error.StatusData   = "Error";
                error.StringBuffer = "Error";
                webSession.Send(error);
            }
            catch (Exception ex)
            {
                Utils.WriteException(ex);
            }
            finally
            {
                AllowSystemStandBy();
            }
        }
예제 #6
0
 private void CloseSink(HTTPSession s)
 {
     lock (this.SessionTable)
     {
         this.SessionTable.Remove(s);
     }
 }
예제 #7
0
        private void CreateFailedSink(HTTPSession ss)
        {
            lock (TagQueue)
            {
                while (TagQueue.Count > 0)
                {
                    StateData sd = (StateData)TagQueue.Dequeue();
                    OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.Error, "Connection Attempt to [" + sd.Dest.ToString() + "] Refused/Failed");

                    object Tag = sd.Tag;
                    if (sd.HeaderCB != null)
                    {
                        sd.HeaderCB(this, ss, null, null, Tag);
                    }
                    else
                    {
                        if (this.OnResponse != null)
                        {
                            OnResponse(this, null, Tag);
                        }
                    }
                }
                s = null;
            }
        }
예제 #8
0
        private void Accept(IAsyncResult result)
        {
            HTTPSession session = null;

            try
            {
                Socket theSocket = this.MainSocket.EndAccept(result);
                lock (this.SessionTable)
                {
                    session                    = new HTTPSession(this.LocalIPEndPoint, theSocket);
                    session.OnClosed          += new HTTPSession.SessionHandler(this.CloseSink);
                    session.OnHeader          += new HTTPSession.ReceiveHeaderHandler(this.HandleHeader);
                    session.OnReceive         += new HTTPSession.ReceiveHandler(this.HandleRequest);
                    this.SessionTable[session] = session;
                }
                this.SessionTimer.Add(session, 3);
                this.OnSessionEvent.Fire(this, session);
                session.StartReading();
            }
            catch (Exception exception)
            {
                if (exception.GetType() != typeof(ObjectDisposedException))
                {
                    EventLogger.Log(exception);
                }
            }
            try
            {
                this.MainSocket.BeginAccept(new AsyncCallback(this.Accept), null);
            }
            catch (Exception)
            {
            }
        }
예제 #9
0
        private void ReceiveSink(HTTPSession sender, HTTPMessage msg)
        {
            StateData stateObject = (StateData)sender.StateObject;
            object    tag         = stateObject.Tag;

            if ((msg.Version == "1.0") || (msg.Version == "0.9"))
            {
                sender.Close();
            }
            else if (msg.GetTag("Connection").ToUpper() == "CLOSE")
            {
                sender.Close();
            }
            if (this.OnResponse != null)
            {
                this.OnResponse(this, msg, tag);
            }
            sender.StateObject = null;
            lock (this.TagQueue)
            {
                if (this.TagQueue.Count == 0)
                {
                    this.IdleTimeout = true;
                    KeepAliveTimer.Add(this.GetHashCode(), 10);
                }
            }
        }
예제 #10
0
        private void HeaderSink(HTTPSession sender, HTTPMessage header, Stream TheStream)
        {
            this._Source = sender.Source;
            StateData stateObject = null;

            if (TheStream != null)
            {
                stateObject = (StateData)sender.StateObject;
                object tag = stateObject.Tag;
                if (stateObject.HeaderCB != null)
                {
                    stateObject.HeaderCB(this, sender, header, TheStream, tag);
                }
                sender.StateObject = null;
                KeepAliveTimer.Add(this.GetHashCode(), 10);
            }
            else
            {
                lock (this.TagQueue)
                {
                    stateObject = (StateData)this.TagQueue.Dequeue();
                }
                sender.StateObject = stateObject;
                object obj3 = stateObject.Tag;
                if (stateObject.HeaderCB != null)
                {
                    stateObject.HeaderCB(this, sender, header, TheStream, obj3);
                    if ((sender.UserStream != null) && !sender.IsChunked)
                    {
                        sender.StateObject = null;
                    }
                }
            }
        }
예제 #11
0
 private void RequestAnsweredSink(HTTPSession ss)
 {
     lock (this.TagQueue)
     {
         if (!this.ReceivedFirstResponse)
         {
             this.ReceivedFirstResponse = true;
             foreach (StateData data in this.TagQueue)
             {
                 try
                 {
                     if (this.ProxySetting == null)
                     {
                         ss.Send(data.Request);
                     }
                     else
                     {
                         HTTPMessage packet = (HTTPMessage)data.Request.Clone();
                         packet.DirectiveObj = "http://" + data.Dest.ToString() + packet.DirectiveObj;
                         packet.Version      = "1.0";
                         ss.Send(packet);
                     }
                     continue;
                 }
                 catch (Exception)
                 {
                     continue;
                 }
             }
         }
     }
 }
예제 #12
0
        private void CloseSink(HTTPSession ss)
        {
            bool   err     = false;
            string erraddr = "";

            ss.CancelAllEvents();
            lock (TagQueue)
            {
                KeepAliveTimer.Remove(this.GetHashCode());

                if (TagQueue.Count > 0)
                {
                    OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.Information, "Switching Pipeline Modes [" + ss.GetHashCode().ToString() + "]");
                    _PIPELINE = false;
                    if (!ReceivedFirstResponse)
                    {
                        erraddr = ((StateData)TagQueue.Peek()).Dest.ToString();
                    }
                }

                if (!ReceivedFirstResponse)
                {
                    OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.Error, "Server[" + erraddr + "] closed socket without answering");
                    err = true;
                }

                while (TagQueue.Count > 0)
                {
                    StateData sd = (StateData)TagQueue.Dequeue();
                    if (!err)
                    {
                        HTTPRequest TR = new HTTPRequest();
                        TR.ProxySetting = ProxySetting;
                        TR._PIPELINE    = true;
                        if (this.OnSniff != null)
                        {
                            TR.OnSniff += new HTTPRequest.SniffHandler(NonPipelinedSniffSink);
                        }
                        if (this.OnSniffPacket != null)
                        {
                            TR.OnSniffPacket += new HTTPRequest.RequestHandler(NonPipelinedSniffPacketSink);
                        }
                        TR.OnResponse += new HTTPRequest.RequestHandler(NonPipelinedResponseSink);
                        this.NotPipelinedTable[TR] = TR;
                        TR.PipelineRequest(sd.Dest, sd.Request, sd.Tag);
                    }
                    else
                    {
                        if (OnResponse != null)
                        {
                            OnResponse(this, null, sd.Tag);
                        }
                    }
                }
                s = null;
            }
        }
 private void Request(object msg, IPEndPoint dest)
 {
     if (dest == null)
     {
         return;
     }
     s = new HTTPSession(new IPEndPoint(IPAddress.Any, 0), dest,
                         new HTTPSession.SessionHandler(CreateSink),
                         new HTTPSession.SessionHandler(FailSink),
                         msg);
 }
예제 #14
0
 public override void Use(HTTPSession session, string[] args)
 {
     if (args.Length < 2)
     {
         session.Session.owner.Send(HackLinksCommon.NetUtil.PacketType.MESSG, "Password required");
         return;
     }
     if (args[1] == password)
     {
         RunAction(session, args);
     }
 }
예제 #15
0
 /// <summary>
 /// Terminates and disposes this object
 /// </summary>
 public void Dispose()
 {
     lock (this.TagQueue)
     {
         HTTPSession x = this.s;
         if (x != null)
         {
             x.Close();
         }
         s = null;
         TagQueue.Clear();
     }
 }
예제 #16
0
 public void Dispose()
 {
     lock (this.TagQueue)
     {
         HTTPSession s = this.s;
         if (s != null)
         {
             s.Close();
         }
         this.s = null;
         this.TagQueue.Clear();
     }
 }
예제 #17
0
        private void RunAction(HTTPSession session, string[] args)
        {
            var actionData = action.Split(new char[] { ':' }, 2);

            if (actionData[0] == "goto")
            {
                if (actionData.Length < 2)
                {
                    return;
                }
                session.SetActivePage(session.Daemon.GetPage(actionData[1]));
            }
        }
예제 #18
0
        private void CloseSink(HTTPSession ss)
        {
            bool   flag = false;
            string str  = "";

            ss.CancelAllEvents();
            lock (this.TagQueue)
            {
                KeepAliveTimer.Remove(this.GetHashCode());
                if (this.TagQueue.Count > 0)
                {
                    EventLogger.Log(this, EventLogEntryType.Information, "Switching Pipeline Modes [" + ss.GetHashCode().ToString() + "]");
                    this._PIPELINE = false;
                    if (!this.ReceivedFirstResponse)
                    {
                        str = ((StateData)this.TagQueue.Peek()).Dest.ToString();
                    }
                }
                if (!this.ReceivedFirstResponse)
                {
                    EventLogger.Log(this, EventLogEntryType.Error, "Server[" + str + "] closed socket without answering");
                    flag = true;
                }
                while (this.TagQueue.Count > 0)
                {
                    StateData data = (StateData)this.TagQueue.Dequeue();
                    if (!flag)
                    {
                        HTTPRequest request = new HTTPRequest();
                        request.ProxySetting = this.ProxySetting;
                        request._PIPELINE    = true;
                        if (this.OnSniff != null)
                        {
                            request.OnSniff = (SniffHandler)Delegate.Combine(request.OnSniff, new SniffHandler(this.NonPipelinedSniffSink));
                        }
                        if (this.OnSniffPacket != null)
                        {
                            request.OnSniffPacket = (RequestHandler)Delegate.Combine(request.OnSniffPacket, new RequestHandler(this.NonPipelinedSniffPacketSink));
                        }
                        request.OnResponse = (RequestHandler)Delegate.Combine(request.OnResponse, new RequestHandler(this.NonPipelinedResponseSink));
                        this.NotPipelinedTable[request] = request;
                        request.PipelineRequest(data.Dest, data.Request, data.Tag);
                    }
                    else if (this.OnResponse != null)
                    {
                        this.OnResponse(this, null, data.Tag);
                    }
                }
                this.s = null;
            }
        }
예제 #19
0
        public void authenticate(HttpListenerRequest req, HttpListenerResponse res, HTTPSession session)
        {
            // use the session object to store state between requests
            session["nonce"] = RandomString();
            session["state"] = RandomString();

            // TODO make authentication request

            // TODO insert the redirect URL
            string login_url = null;

            res.Redirect(login_url);
            res.Close();
        }
예제 #20
0
    public void CreateNewSession()
    {
        if (session == null)
        {
            // Create a new one
            session = Server.CreateSession(Global.GenerateCode(12), 60 * 20);

            HTTPResponsePacket.HTTPCookie cookie = new HTTPResponsePacket.HTTPCookie("SID", session.Id);
            cookie.Expires  = DateTime.MaxValue;
            cookie.Path     = "/";
            cookie.HttpOnly = true;

            Response.Cookies.Add(cookie);
        }
    }
예제 #21
0
        private void SniffPacketSink(HTTPSession sender, HTTPMessage MSG)
        {
            if (this.OnSniffPacket != null)
            {
                if (sender.StateObject == null)
                {
                    OnSniffPacket(this, MSG, null);
                    return;
                }
                StateData sd  = (StateData)sender.StateObject;
                object    Tag = sd.Tag;

                OnSniffPacket(this, MSG, Tag);
            }
        }
예제 #22
0
 private void SniffPacketSink(HTTPSession sender, HTTPMessage MSG)
 {
     if (this.OnSniffPacket != null)
     {
         if (sender.StateObject == null)
         {
             this.OnSniffPacket(this, MSG, null);
         }
         else
         {
             StateData stateObject = (StateData)sender.StateObject;
             object    tag         = stateObject.Tag;
             this.OnSniffPacket(this, MSG, tag);
         }
     }
 }
예제 #23
0
        private void CreateSink(HTTPSession ss)
        {
            lock (TagQueue)
            {
                ss.OnHeader          += HeaderSink;
                ss.OnReceive         += ReceiveSink;
                ss.OnClosed          += CloseSink;
                ss.OnStreamDone      += StreamDoneSink;
                ss.OnRequestAnswered += RequestAnsweredSink;

                if (OnSniff != null)
                {
                    ss.OnSniff += SniffSink;
                }
                if (OnSniffPacket != null)
                {
                    ss.OnSniffPacket += SniffPacketSink;
                }

                StateData sd = (StateData)TagQueue.Peek();

                try
                {
                    if (ProxySetting == null)
                    {
                        ss.Send(sd.Request);
                    }
                    else
                    {
                        HTTPMessage pr = (HTTPMessage)sd.Request.Clone();
                        pr.DirectiveObj = "http://" + sd.Dest + pr.DirectiveObj;
                        pr.Version      = "1.0";
                        ss.Send(pr);
                    }
                }
                catch (Exception exc)
                {
                    EventLogger.Log(exc);
                }
            }
        }
예제 #24
0
        private void CreateSink(HTTPSession ss)
        {
            lock (TagQueue)
            {
                ss.OnHeader          += new HTTPSession.ReceiveHeaderHandler(HeaderSink);
                ss.OnReceive         += new HTTPSession.ReceiveHandler(ReceiveSink);
                ss.OnClosed          += new HTTPSession.SessionHandler(CloseSink);
                ss.OnStreamDone      += new HTTPSession.StreamDoneHandler(StreamDoneSink);
                ss.OnRequestAnswered += new HTTPSession.SessionHandler(RequestAnsweredSink);

                if (this.OnSniff != null)
                {
                    ss.OnSniff += new HTTPSession.SniffHandler(SniffSink);
                }
                if (this.OnSniffPacket != null)
                {
                    ss.OnSniffPacket += new HTTPSession.ReceiveHandler(SniffPacketSink);
                }

                StateData sd = (StateData)TagQueue.Peek();

                try
                {
                    if (ProxySetting == null)
                    {
                        ss.Send(sd.Request);
                    }
                    else
                    {
                        HTTPMessage pr = (HTTPMessage)sd.Request.Clone();
                        pr.DirectiveObj = "http://" + sd.Dest.ToString() + pr.DirectiveObj;
                        pr.Version      = "1.0";
                        ss.Send(pr);
                    }
                }
                catch (Exception exc)
                {
                    OpenSource.Utilities.EventLogger.Log(exc);
                }
            }
        }
예제 #25
0
 private void CreateFailedSink(HTTPSession ss)
 {
     lock (this.TagQueue)
     {
         while (this.TagQueue.Count > 0)
         {
             StateData data = (StateData)this.TagQueue.Dequeue();
             EventLogger.Log(this, EventLogEntryType.Error, "Connection Attempt to [" + data.Dest.ToString() + "] Refused/Failed");
             object tag = data.Tag;
             if (data.HeaderCB != null)
             {
                 data.HeaderCB(this, ss, null, null, tag);
             }
             else if (this.OnResponse != null)
             {
                 this.OnResponse(this, null, tag);
             }
         }
         this.s = null;
     }
 }
예제 #26
0
        private void Accept(IAsyncResult result)
        {
            HTTPSession WebSession;

            try
            {
                Socket AcceptedSocket = MainSocket.EndAccept(result);
                lock (SessionTable)
                {
                    WebSession               = new HTTPSession(LocalIPEndPoint, AcceptedSocket);
                    WebSession.OnClosed     += CloseSink;
                    WebSession.OnHeader     += HandleHeader;
                    WebSession.OnReceive    += HandleRequest;
                    SessionTable[WebSession] = WebSession;
                }
                SessionTimer.Add(WebSession, 3);
                OnSessionEvent.Fire(this, WebSession);
                WebSession.StartReading();
            }
            catch (Exception err)
            {
                if (err.GetType() != typeof(ObjectDisposedException))
                {
                    // Error
                    EventLogger.Log(err);
                }
            }

            try
            {
                MainSocket.BeginAccept(Accept, null);
            }
            catch (Exception ex)
            {
                EventLogger.Log(ex);
                // Socket was closed
            }
        }
예제 #27
0
 private void CreateSink(HTTPSession ss)
 {
     lock (this.TagQueue)
     {
         ss.OnHeader          += new HTTPSession.ReceiveHeaderHandler(this.HeaderSink);
         ss.OnReceive         += new HTTPSession.ReceiveHandler(this.ReceiveSink);
         ss.OnClosed          += new HTTPSession.SessionHandler(this.CloseSink);
         ss.OnStreamDone      += new HTTPSession.StreamDoneHandler(this.StreamDoneSink);
         ss.OnRequestAnswered += new HTTPSession.SessionHandler(this.RequestAnsweredSink);
         if (this.OnSniff != null)
         {
             ss.OnSniff += new HTTPSession.SniffHandler(this.SniffSink);
         }
         if (this.OnSniffPacket != null)
         {
             ss.OnSniffPacket += new HTTPSession.ReceiveHandler(this.SniffPacketSink);
         }
         StateData data = (StateData)this.TagQueue.Peek();
         try
         {
             if (this.ProxySetting == null)
             {
                 ss.Send(data.Request);
             }
             else
             {
                 HTTPMessage packet = (HTTPMessage)data.Request.Clone();
                 packet.DirectiveObj = "http://" + data.Dest.ToString() + packet.DirectiveObj;
                 packet.Version      = "1.0";
                 ss.Send(packet);
             }
         }
         catch (Exception exception)
         {
             EventLogger.Log(exception);
         }
     }
 }
        private void Accept(IAsyncResult result)
        {
            HTTPSession WebSession = null;

            try
            {
                Socket AcceptedSocket = MainSocket.EndAccept(result);
                lock (SessionTable)
                {
                    WebSession               = new HTTPSession(this.LocalIPEndPoint, AcceptedSocket);
                    WebSession.OnClosed     += new HTTPSession.SessionHandler(CloseSink);
                    WebSession.OnHeader     += new HTTPSession.ReceiveHeaderHandler(HandleHeader);
                    WebSession.OnReceive    += new HTTPSession.ReceiveHandler(HandleRequest);
                    SessionTable[WebSession] = WebSession;
                }
                SessionTimer.Add(WebSession, 3);
                OnSessionEvent.Fire(this, WebSession);
                WebSession.StartReading();
            }
            catch (Exception err)
            {
                if (err.GetType() != typeof(System.ObjectDisposedException))
                {
                    // Error
                    OpenSource.Utilities.EventLogger.Log(err);
                }
            }

            try
            {
                MainSocket.BeginAccept(new AsyncCallback(Accept), null);
            }
            catch (Exception ex)
            {
                OpenSource.Utilities.EventLogger.Log(ex);
                // Socket was closed
            }
        }
        private void CreateSink(HTTPSession CS)
        {
            CS.OnClosed += new HTTPSession.SessionHandler(CloseSink);

            SW            = new HTTPSessionWatcher(CS);
            SW.OnSniff   += new HTTPSessionWatcher.SniffHandler(SniffSink);
            CS.OnReceive += new HTTPSession.ReceiveHandler(ReceiveSink);
            if (CS.StateObject.GetType() == typeof(HTTPMessage))
            {
                CS.Send((HTTPMessage)CS.StateObject);
            }
            else
            {
                Queue       Q = (Queue)CS.StateObject;
                HTTPMessage M;
                M = (HTTPMessage)Q.Dequeue();
                while (M != null && Q.Count > 0)
                {
                    CS.Send(M);
                    M = (HTTPMessage)Q.Dequeue();
                }
            }
        }
예제 #30
0
    // Use this for initialization
    void Start()
    {
        session             = new HTTPSession("http://goshit.luzexi.com/index.php/");
        session.onDataError = showError;
        Hashtable head = new Hashtable();

        head["cookie"]    = "ok123";
        head["token"]     = "123";
        session.m_cHeader = head;

        TestReq req = new TestReq();

        req.arg1 = "1";
        req.arg2 = 0;
        req.arg3 = 0.3f;

        session.SendGET(req, (TestAck ack) => {
            Debug.Log("ok");
            Debug.Log("username: "******"password : "******" token : " + ack.data.token);
        });
    }
예제 #31
0
파일: AVPlayList.cs 프로젝트: Scannow/SWYH
 /// <summary>
 /// This method gets called when we are done streaming the media
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="S"></param>
 protected void DoneSink(HTTPSession sender, Stream S)
 {
     sender.CloseStreamObject(S);
     sender.Close();
 }
예제 #32
0
파일: AVPlayList.cs 프로젝트: Scannow/SWYH
        /// <summary>
        /// This method gets called when a new Request is received
        /// </summary>
        /// <param name="request"></param>
        /// <param name="WebSession"></param>
        protected void ReceiveSink(HTTPMessage request, HTTPSession WebSession)
        {
            HTTPMessage rsp = new HTTPMessage();
            UTF8Encoding U = new UTF8Encoding();

            if ((request.Directive == "HEAD") ||
                (request.Directive == "GET"))
            {
                if (request.DirectiveObj == "/item.m3u")
                {/*
					rsp.StatusCode = 200;
					rsp.StatusData = "OK";
					rsp.ContentType = "audio/mpegurl";
					rsp.StringBuffer = M3UString;
					*/

                    string r = request.GetTag("Range");
                    if (r == "")
                    {
                        rsp.StatusCode = 200;
                        rsp.StatusData = "OK";
                        rsp.ContentType = "audio/mpegurl";
                        rsp.StringBuffer = M3UString;
                    }
                    else
                    {
                        rsp.StatusCode = 206;
                        rsp.StatusData = "Partial Content";
                        rsp.ContentType = "audio/mpegurl";

                        DText rp0 = new DText();
                        rp0.ATTRMARK = "=";
                        rp0[0] = r;
                        DText rp = new DText();
                        rp.ATTRMARK = "-";
                        rp[0] = rp0[2].Trim();
                        if (rp[1] == "")
                        {
                            // LastBytes
                            try
                            {
                                if (int.Parse(rp[2]) > M3UString.Length)
                                {
                                    rsp.AddTag("Content-Range", "bytes 0-" + M3UString.Length.ToString() + "/" + M3UString.Length.ToString());
                                    rsp.StringBuffer = M3UString;
                                }
                                else
                                {
                                    rsp.AddTag("Content-Range", "bytes " + (M3UString.Length - int.Parse(rp[2])).ToString() + "-" + M3UString.Length.ToString() + "/" + M3UString.Length.ToString());
                                    rsp.StringBuffer = M3UString.Substring(M3UString.Length - int.Parse(rp[2]));
                                }
                            }
                            catch (Exception)
                            {
                                rsp = new HTTPMessage();
                                rsp.StatusCode = 400;
                                rsp.StatusData = "Bad Request";
                            }
                        }
                        else if (rp[2] == "")
                        {
                            // Offset till end
                            try
                            {
                                rsp.AddTag("Content-Range", "bytes " + rp[1] + "-" + M3UString.Length.ToString() + "/" + M3UString.Length.ToString());
                                rsp.StringBuffer = M3UString.Substring(int.Parse(rp[1]));
                            }
                            catch (Exception)
                            {
                                rsp = new HTTPMessage();
                                rsp.StatusCode = 400;
                                rsp.StatusData = "Bad Request";
                            }

                        }
                        else
                        {
                            // Range
                            try
                            {
                                if (int.Parse(rp[2]) > M3UString.Length + 1)
                                {
                                    rsp.AddTag("Content-Range", "bytes " + rp[1] + "-" + (M3UString.Length - 1).ToString() + "/" + M3UString.Length.ToString());
                                    rsp.StringBuffer = M3UString.Substring(int.Parse(rp[1]));
                                }
                                else
                                {
                                    rsp.AddTag("Content-Range", "bytes " + rp[1] + "-" + rp[2] + "/" + M3UString.Length.ToString());
                                    rsp.StringBuffer = M3UString.Substring(int.Parse(rp[1]), 1 + int.Parse(rp[2]) - int.Parse(rp[1]));
                                }
                            }
                            catch (Exception)
                            {
                                rsp = new HTTPMessage();
                                rsp.StatusCode = 400;
                                rsp.StatusData = "Bad Request";
                            }
                        }
                    }
                }
                else
                {
                    try
                    {
                        int i = request.DirectiveObj.LastIndexOf("/");
                        string tmp = request.DirectiveObj.Substring(1, i - 1);
                        bool hasRange = true;
                        if (tmp.IndexOf("/") != -1)
                        {
                            tmp = tmp.Substring(0, tmp.IndexOf("/"));
                        }

                        if (FileInfoTable.ContainsKey(tmp))
                        {
                            FileInfo f;
                            if (FileInfoTable[tmp].GetType() == typeof(string))
                            {
                                f = new FileInfo((string)FileInfoTable[tmp]);
                                FileInfoTable[tmp] = f;
                            }
                            else
                            {
                                f = (FileInfo)FileInfoTable[tmp];
                            }
                            ProtocolInfoString pis = ProtocolInfoString.CreateHttpGetProtocolInfoString(f);
                            rsp.StatusCode = 200;
                            rsp.StatusData = "OK";
                            rsp.ContentType = pis.MimeType;
                            if (request.Directive == "HEAD")
                            {
                                rsp.AddTag("Content-Length", f.Length.ToString());
                                rsp.OverrideContentLength = true;
                            }
                            else
                            {
                                HTTPSession.Range[] RNG = null;
                                if (request.GetTag("Range") != "")
                                {
                                    long x, y;
                                    ArrayList RList = new ArrayList();
                                    DText rp = new DText();
                                    rp.ATTRMARK = "=";
                                    rp.MULTMARK = ",";
                                    rp.SUBVMARK = "-";
                                    rp[0] = request.GetTag("Range");

                                    for (int I = 1; I <= rp.DCOUNT(2); ++I)
                                    {
                                        if (rp[2, I, 1] == "")
                                        {
                                            // Final Bytes
                                            y = long.Parse(rp[2, I, 2].Trim());
                                            x = f.Length - y;
                                            y = x + y;
                                        }
                                        else if (rp[2, I, 2] == "")
                                        {
                                            // Offset till end
                                            x = long.Parse(rp[2, I, 1].Trim());
                                            y = f.Length - x;
                                        }
                                        else
                                        {
                                            // Full Range
                                            x = long.Parse(rp[2, I, 1].Trim());
                                            y = long.Parse(rp[2, I, 2].Trim());
                                        }
                                        RList.Add(new HTTPSession.Range(x, 1 + y - x));
                                    }
                                    RNG = (HTTPSession.Range[])RList.ToArray(typeof(HTTPSession.Range));
                                }
                                else
                                {
                                    hasRange = false;
                                }

                                if (request.Version == "1.0")
                                {
                                    WebSession.OnStreamDone += new HTTPSession.StreamDoneHandler(DoneSink);
                                }
                                //								((HTTPMessage)(new UPnPDebugObject(WebSession)).GetField("Headers")).Version = "1.0";
                                if (hasRange)
                                {
                                    WebSession.SendStreamObject(f.OpenRead(), RNG, pis.MimeType);
                                }
                                else
                                {
                                    FileStream fs = f.OpenRead();
                                    long length = fs.Length;
                                    WebSession.SendStreamObject(fs, length, pis.MimeType);
                                }
                                return;
                            }
                        }
                        else
                        {
                            rsp.StatusCode = 404;
                            rsp.StatusData = "Not Found";
                        }
                    }
                    catch (Exception)
                    {
                        rsp.StatusCode = 404;
                        rsp.StatusData = "Not Found";
                    }
                }
                WebSession.Send(rsp);
                return;
            }

            rsp.StatusCode = 500;
            rsp.StatusData = "Not implemented";
            WebSession.Send(rsp);
        }