Example #1
0
        private void ReturnXML_Info(MyHttpListenerRequest req, MyHttpListenerResponse res)
        {
            var useGzip = req.Headers["Accept-Encoding"].Split(',').Contains("gzip");

            if (useGzip)
            {
                res.AppendHeader("Content-Encoding", "gzip");
            }

            byte[] xml = CachedXML_Info;
            if (xml == null)
            {
                var doc   = new System.Xml.XmlDocument();
                var lutea = doc.CreateElement("lutea");
                doc.AppendChild(lutea);
                var comet_id = doc.CreateElement("comet_id");
                lutea.AppendChild(comet_id);

                // 現在のトラックに関する情報をセット
                var current = doc.CreateElement("current");
                foreach (var e in Controller.Columns)
                {
                    var ele = doc.CreateElement(e.ToString());
                    ele.InnerText = Controller.Current.MetaData(e);
                    current.AppendChild(ele);
                }
                lutea.AppendChild(current);

                // playlist生成クエリ文字列をセット
                var playlistquery = doc.CreateElement("playlistQuery");
                playlistquery.InnerText = Controller.LatestPlaylistQuery;
                lutea.AppendChild(playlistquery);

                // cometセッション識別子セット
                comet_id.InnerText = GetCometContext_XMLInfo().ToString();

                var ms = new System.IO.MemoryStream();
                var xw = new System.Xml.XmlTextWriter(ms, Encoding.UTF8);
                doc.Save(xw);
                xml = CachedXML_Info = ms.GetBuffer().Take((int)ms.Length).ToArray();
            }

            using (var os = res.OutputStream)
                using (var gzips = new System.IO.Compression.GZipStream(os, System.IO.Compression.CompressionMode.Compress))
                {
                    try
                    {
                        (useGzip ? gzips : os).Write(xml, 0, xml.Length);
                    }
                    catch { }
                }
            res.Close();
        }
Example #2
0
        private MyHttpListenerContext parseHTTPRequest(TcpClient tcpc)
        {
            var strm        = tcpc.GetStream();
            var requestLine = readOneLine(strm);

            if (requestLine == null)
            {
                return(null);
            }
            var requestTokens = requestLine.Split(' ');

            Logger.Log(requestTokens[1]);
            MyHttpListenerRequest  req = new MyHttpListenerRequest();
            MyHttpListenerResponse res = new MyHttpListenerResponse(strm, tcpc);

            if (requestTokens[1].Contains('?'))
            {
                var queryStringAll = requestTokens[1].Substring(requestTokens[1].IndexOf('?') + 1).Split('&');
                foreach (var q in queryStringAll)
                {
                    var kv = q.Split('=');
                    if (kv.Length != 2)
                    {
                        continue;
                    }
                    req.QueryString.Add(kv[0], kv[1]);
                }
            }
            string line;

            while ((line = readOneLine(strm)) != "")
            {
                var kv = line.Split(new char[] { ':' }, 2);
                if (kv.Length != 2)
                {
                    continue;
                }
                req.Headers.Add(kv[0].Trim(), kv[1].Trim());
            }
            return(new MyHttpListenerContext(req, res));
        }
Example #3
0
        private void ReturnXML_Playlist(MyHttpListenerRequest req, MyHttpListenerResponse res)
        {
            var useGzip = req.Headers["Accept-Encoding"].Split(',').Contains("gzip");

            if (useGzip)
            {
                res.AppendHeader("Content-Encoding", "gzip");
            }

            byte[] xml = CachedXML_Playlist;
            lock (this)
            {
                if (xml == null)
                {
                    var doc   = new System.Xml.XmlDocument();
                    var lutea = doc.CreateElement("lutea");
                    doc.AppendChild(lutea);
                    var comet_id = doc.CreateElement("comet_id");
                    lutea.AppendChild(comet_id);

                    var playlist = doc.CreateElement("playlist");
                    var cifn     = Controller.GetColumnIndexByName(Library.LibraryDBColumnTextMinimum.file_name);
                    var cital    = Controller.GetColumnIndexByName("tagAlbum");
                    var citar    = Controller.GetColumnIndexByName("tagArtist");
                    var citt     = Controller.GetColumnIndexByName("tagTitle");

                    for (int i = 0; i < Controller.PlaylistRowCount; i++)
                    {
                        var row = Controller.GetPlaylistRow(i);
                        if (row == null || row.Length <= 1)
                        {
                            continue;
                        }
                        var item = doc.CreateElement("item");
                        item.SetAttribute("file_name", (row[cifn] ?? "").ToString());
                        item.SetAttribute("tagAlbum", (row[cital] ?? "").ToString());
                        item.SetAttribute("tagArtist", (row[citar] ?? "").ToString());
                        item.SetAttribute("tagTitle", (row[citt] ?? "").ToString());
                        playlist.AppendChild(item);
                    }

                    lutea.AppendChild(playlist);

                    // cometセッション識別子セット
                    comet_id.InnerText = GetCometContext_XMLPlaylist().ToString();

                    var ms = new System.IO.MemoryStream();
                    var xw = new System.Xml.XmlTextWriter(ms, Encoding.UTF8);
                    doc.Save(xw);
                    xml = CachedXML_Playlist = ms.GetBuffer().Take((int)ms.Length).ToArray();
                }
            }

            using (var os = res.OutputStream)
                using (var gzips = new System.IO.Compression.GZipStream(os, System.IO.Compression.CompressionMode.Compress))
                {
                    try
                    {
                        (useGzip ? gzips : os).Write(xml, 0, xml.Length);
                    }
                    catch { }
                }
            res.Close();
        }
Example #4
0
 internal MyHttpListenerContext(MyHttpListenerRequest req, MyHttpListenerResponse res)
 {
     request  = req;
     response = res;
 }