public override DreamAccess DetermineAccess(DreamContext context, DreamMessage request) { if (context.Feature.Signature.StartsWith("subscribers/")) { string id = context.GetParam("id", null); PubSubSubscriptionSet set = _dispatcher[id]; if (set != null) { string accessKey = context.GetParam("access-key", null); if (string.IsNullOrEmpty(accessKey)) { DreamCookie cookie = DreamCookie.GetCookie(request.Cookies, "access-key"); if (cookie != null) { accessKey = cookie.Value; } } if (StringUtil.EqualsInvariant(set.AccessKey, accessKey)) { return(DreamAccess.Private); } _log.DebugFormat("no matching access-key in query or cookie for location '{0}'", id); } else { _log.DebugFormat("no subscription set for location '{0}'", id); } } return(base.DetermineAccess(context, request)); }
protected Yield GetSubscribeSet(DreamContext context, DreamMessage request, Result <DreamMessage> response) { PubSubSubscriptionSet set = _dispatcher[context.GetParam("id")]; if (set == null) { response.Return(DreamMessage.NotFound("There is no subscription set at this location")); } else { response.Return(DreamMessage.Ok(set.AsDocument())); } yield break; }
protected Yield ReplaceSubscribeSet(DreamContext context, DreamMessage request, Result <DreamMessage> response) { try { string setId = context.GetParam("id"); _log.DebugFormat("Updating set {0}", setId); if (!string.IsNullOrEmpty(request.Headers.DreamEventId)) { _log.DebugFormat("'{0}' update is event: {1} - {2}", setId, request.Headers.DreamEventChannel, request.Headers.DreamEventId); } XDoc subscriptionDocument = request.ToDocument(); PubSubSubscriptionSet set = _dispatcher.ReplaceSet(setId, subscriptionDocument); if (set != null) { long?version = subscriptionDocument["@version"].AsLong; if (version.HasValue && version.Value <= set.Version) { _log.DebugFormat("set not modified: {0}", setId); response.Return(DreamMessage.NotModified()); } else { if (version.HasValue) { _log.DebugFormat("Updating set '{0}' from version {1} to {2}", setId, set.Version, version); } else { _log.DebugFormat("Updating set '{0}'", setId); } response.Return(DreamMessage.Ok()); } } else { _log.DebugFormat("no such set: {0}", setId); response.Return(DreamMessage.NotFound("There is no subscription set at this location")); } } catch (ArgumentException e) { response.Return(DreamMessage.Forbidden(e.Message)); } yield break; }