private static async Task OnViewXML(IOwinContext ctx, CancellationToken cancel_token) { var data = BuildViewXml(ctx.GetPeerCast()); ctx.Response.StatusCode = (int)HttpStatusCode.OK; ctx.Response.ContentType = "text/xml;charset=utf-8"; ctx.Response.ContentLength = data.LongLength; await ctx.Response.WriteAsync(data, cancel_token).ConfigureAwait(false); }
private static async Task <Channel> GetChannelAsync(IOwinContext ctx, ParsedRequest req, CancellationToken ct) { var tip = ctx.Request.Query.Get("tip"); var channel = ctx.GetPeerCast().RequestChannel(req.ChannelId, OutputStreamBase.CreateTrackerUri(req.ChannelId, tip), true); if (channel == null) { return(null); } using (var cts = CancellationTokenSource.CreateLinkedTokenSource(ct)) { cts.CancelAfter(10000); await channel.WaitForReadyContentTypeAsync(cts.Token).ConfigureAwait(false); } return(channel); }
private static async Task InvokeIndexTXT(IOwinContext ctx) { var cancel_token = ctx.Request.CallCancelled; ctx.Response.ContentType = "text/plain;charset=utf-8"; var acinfo = ctx.GetAccessControlInfo(); if (acinfo?.AuthenticationKey != null) { ctx.Response.Headers.Append("Set-Cookie", $"auth={acinfo.AuthenticationKey.GetToken()}; Path=/"); } var peercast = ctx.GetPeerCast(); var indextxt = String.Join("\r\n", peercast.Channels.Select(c => BuildIndexTXTEntry(peercast, c))); await ctx.Response.WriteAsync(indextxt, cancel_token).ConfigureAwait(false); }
private static async Task OnStop(IOwinContext ctx, CancellationToken cancel_token) { var peercast = ctx.GetPeerCast(); var channel = FindChannelFromQuery(ctx); if (channel != null) { peercast.CloseChannel(channel); ctx.Response.StatusCode = (int)HttpStatusCode.OK; await ctx.Response.WriteAsync("OK", cancel_token).ConfigureAwait(false); } else { ctx.Response.StatusCode = (int)HttpStatusCode.NotFound; await ctx.Response.WriteAsync("Channel NotFound", cancel_token).ConfigureAwait(false); } }
private static Channel FindChannelFromQuery(IOwinContext ctx) { var peercast = ctx.GetPeerCast(); var idstr = ctx.Request.Query.Get("id"); if (peercast != null && idstr != null) { var md = System.Text.RegularExpressions.Regex.Match(idstr, @"([A-Fa-f0-9]{32})(\.\S+)?"); var channel_id = Guid.Empty; if (md.Success) { try { channel_id = new Guid(md.Groups[1].Value); } catch (Exception) { } } return(peercast.Channels.FirstOrDefault(c => c.ChannelID == channel_id)); } else { return(null); } }